@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20



Comments:

<0> :%s/\(use\)\ use/\1/
<0> so, any ideas on my copy issues - anyone? :/
<1> mcmillen_: if you use emacs, he has support for create PS from (syntax highlghted) buffers .. otherwise as ppl say, use one of these code formatters
<2> pydog - thanks, code2html seems good enough for now :)
<2> and thanks everyone else for suggestions
<3> pydog: where are the lists stored, on the instances or the cl***es?
<1> pydog: as i said .. dont use static vars
<4> Man, that was a most convoluted subregexp where "s/use //" woulda done. :)
<0> :)
<1> pydog: create them in the __init__, otherwise they are ref's used by all instances of the cl***
<0> pjd: i have them defined in the cl***, so cl*** X: __foo=[];
<0> oh
<3> pydog: deepcopy only copies the instances (and everything in them), not the cl***es
<5> hi! I am checking up with gnome.ui.About. It's working fine with me. but i want to remove gnome logo from the window which is coming up. any hints how to do that ?
<0> hang on...
<3> pydog: also, you probably want to check with: A.__foo is B.__foo is C.__foo



<0> ok, I have X.__bar (type datetime)
<3> because even when the lists are copied, they will still be ==
<3> (until the copies get changed)
<0> I have X.__foo (type list)
<0> X.__bar is fine
<0> bu the lists are all references to the same list
<6> pfote: http://www.peterbe.com/plog/html-entity-fixer
<0> and the copies are being changed
<4> pydog, we understand that.
<0> http://pastebin.com/588802
<3> pydog: when you say "cl*** X: __foo=[]", the list is contained on the cl*** object, not the instance
<0> (FixAttr is a cl*** I wrote to inherit from to stop changine any member from one type to another)
<0> pjd: then how is it that two instances have two different .__bar (type datetime)s?
<3> pydog: because those are contained on the instances
<0> I'm not saying you are wrong - just trying to understand
<0> why is __bar in the instance, and __foo in the cl***?
<0> I defined both outside of the __init__ fn
<3> because you ***igned one to the cl***, and one to the instance
<0> wrt pastebin, line 7 vs 8,9,10,11
<3> you actually have two __date's
<1> pythonologist: i see, tnx
<0> how have i done that? implicitely?
<3> one on the cl*** (line 7)
<3> and one on the instance (line 14)
<7> how do i remove the title bar of a window in Tkinter?
<3> when you *read* self.__date, python first looks in the instance
<0> they're the same
<3> and if it doesn't find __date on the instance, it looks on the cl***
<4> pydog, you have shadowing on __date.
<0> if I dir the object, are you saying there should be two date objects?
<3> and if it doesn't find it there, it fails with a AttributeError
<3> pydog: no, you only see one
<0> right
<3> the instance one hides the cl*** one
<4> You only *see* the instance copy.
<0> right... that sheds some light
<3> pydog: for example, if you say "del self.__date"
<3> that will delete the instance's copy
<0> ahhh
<3> but then, you'll see the cl***'s copy instead
<4> Or you print Day.__date
<3> (if you try to access self.__date after the del)
<0> yes you are most definitely right. Thankyou pjd
<0> and hari
<0> now, to fix the broken
<3> pydog: usually, you want all attributes on the instance
<3> so it's a good idea to initialize all of them in __init__
<3> (by ***igning to self)
<3> a good habit, i mean
<3> only put stuff on the cl*** where you know you only need one shared copy
<3> for example, special/constant values
<0> fixed - thankyou guys for the explanation and detail =)
<0> I only put it in the cl*** because of the FixAttr cl*** requirement
<0> ie can't add or delete object members
<0> or change their types
<0> eg `int i = 0; i = "fred" --> breaks`
<4> Sounds like a way to depythonify python.
<3> pydog: what is FixAttr exactly?
<0> well maybe, but on complicated objects its nice to fix some things, i mean __setattr__ and __getattr__ etc are there for such things, just not defaulted in such ways
<3> but like hari` said, restricting the types is almost certainly a bad idea



<3> for example, when an int becomes a long, stuff will break
<4> Or when a ref goes None. ;)
<3> when you try to use proxy objects, stuff will break
<0> pjd: http://pastebin.com/588820
<4> Much better to just write unit tests and bang the hell out of them.
<3> basically, you throw away a whole bunch of common real-world usefulness
<0> pjd I agree for most cases, but in this object, I know exactly what the types are, and ever should be
<3> pydog: then it sounds like you want properties, instead
<0> why is it still bad to fix it?
<4> Then it will be easy to write code that maintains that contract. ;)
<3> pydog: for the ones that are fixedly typed
<0> well, I am using properties... sort of
<3> no, i mean actual properties
<0> less mess this way though
<3> descriptor objects
<3> but even then, it sounds overly optimistic to me saying you know exactly what the types are, and ever should be :)
<3> you might know the behaviour and interfaces that are, and ever should be
<3> but remember that python types/cl***es are about implementation, not behavior/interface
<3> it's not uncommon to use completely different types for the same implementation/behavior
<3> so you might have a attribute that's an "integer", logically
<8> hello, I have a question about the first example in the Socket HOWTO. What is needed so that the server does not shut down when the client connects?
<3> but its implementation type can be int, or long, or some numeric python/gmpy integer implementation, or a database-backed int type, or a proxy object for debugging, or things like POSH, or weak references...
<8> http://www.python.org/doc/2.4.2/lib/socket-example.html
<3> you get the idea
<3> and that's just for integers
<0> you talk of polymorphism right?
<3> eh, not in the java/C++ sense of the word
<0> so any object will do for what i want, as long as it does X, Y and Z, hence the badness of isinstance() and type() use ?
<3> pretty much :)
<3> just use the objects
<3> if they're the wrong type, they'll raise an error
<0> yeah, ok... well maybe after it is all working, I'll feel happy that its doing the right thing, then go back and de-FixAttr it
<3> pydog: i think you really want to look at the adaptation/protocol implementations for python
<0> do you have a uri?
<3> they do the kind of typechecking that you want, but in a useful and much more powerful way
<3> http://peak.telecommunity.com/PyProtocols.html
<3> http://www.python.org/peps/pep-0246.html
<3> and http://www.zope.org/Wikis/Interfaces/FrontPage
<3> the basic idea is that you define interfaces/protocols for things like "integer"
<3> and then different types/objects can either declare themselves as implementing that interface
<3> or they can declare an adapter, which transforms them into an object with that interface
<3> so instead of typechecking in your cl***
<3> you just say "ok, this must be an integer"
<0> right
<3> and the adaptation framework will make sure that you get an integer, possibly by calling the necessary adapters, or whatever
<3> or it fails
<0> do you have an example code somewhere? or i should just browse for it on python.org?
<3> the pyprotocols page has a tutorial
<0> yeah loks like i do need to read up on such things
<0> ^o^oo
<3> and the PEAK site in general has a lot of examples and support and such
<3> you'll probably be interested in other parts of PEAK as well
<0> I'll read up on it tomorrow then :) thankyou for the advice & constructive criticism =)
<9> anyone know how to use .NET 2005 for creating extension modules
<9> python still complains it can't find .NET framework :\
<10> is adam here? pm me plz, i need a python script you wrote
<11> I have a cl*** instance, how do I find the name of the cl*** that was instantiated?
<3> HowardTheCoward: type(instance).__name__
<11> pjd, thanks, what about the reverse ? i have a string containing a cl*** name, need to get an instance of that cl***, how?
<3> HowardTheCoward: well, that's a bit more risky, in general
<3> basically, you just need to lookup the name in the appropriate namespace
<11> pjd, i even knew how to do it, but i forgot :)
<3> but you have to know what the "appropriate namespace" is
<3> well, you can say locals()[name]
<3> or globals()[name]
<3> or getattr(somemodule, name)
<11> pjd, btw type(my_instance).__name__ returns 'instance' not the cl*** name
<3> ah, then you're using old-style cl***es
<11> huh ?
<11> it's an instance of a cl*** from a module
<3> yes, but it's an old-style cl***
<11> what to do then ?
<3> if you can, change it to a new-style cl***
<3> by inheriting from object (or saying "__metacl***__ = type" at the top of your file)


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #python
or
Go to some related logs:

chroot /mnt/gentoo Exec format error
ubuntu vbesave
direct reendering
about:googledork
#kde
#ubuntu
gcc auto-parallelization
#osdev
qemu SSE3
goto in bash



Home  |  disclaimer  |  contact  |  submit quotes