Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
mk a écrit : Bruno Desthuilliers wrote: Thanks, that worked. But in order to make it work I had to get rid of 'self' in print_internal_date signature Indeed. Using it that way, the print_internal_date will not be wrapped in a method object. Hold on! How does Python know what to wrap and what

Re: Referring to class methods in class attributes

2010-02-18 Thread Steve Holden
mk wrote: > Bruno Desthuilliers wrote: >>> Thanks, that worked. But in order to make it work I had to get rid of >>> 'self' in print_internal_date signature >> >> Indeed. Using it that way, the print_internal_date will not be wrapped >> in a method object. > > Hold on! How does Python know what to

Re: Referring to class methods in class attributes

2010-02-18 Thread mk
Bruno Desthuilliers wrote: Thanks, that worked. But in order to make it work I had to get rid of 'self' in print_internal_date signature Indeed. Using it that way, the print_internal_date will not be wrapped in a method object. Hold on! How does Python know what to wrap and what not to wrap,

Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
Ben Finney a écrit : Bruno Desthuilliers writes: perhaps a lighter introductory text could be helpful. So guys, if you think a revised version of my post would be of interest, I'll take you on words: provide the hosting, I'll provide the content !-) Here, let me work my hosting magic: http:/

Re: Referring to class methods in class attributes

2010-02-18 Thread Ben Finney
Bruno Desthuilliers writes: > perhaps a lighter introductory text could be helpful. So guys, if you > think a revised version of my post would be of interest, I'll take you > on words: provide the hosting, I'll provide the content !-) Here, let me work my hosting magic: http://wiki.python.org/>.

Re: Referring to class methods in class attributes

2010-02-18 Thread mk
Stephen Hansen wrote: Or just leave it as a top level function where it was perfectly happy to live :) Yes. This is probably the sanest solution anyway, because probably having many such functions to use, packing them into smth like package.utils anyway is a good idea. I'm trying mainly to le

Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
Mark Lawrence a écrit : Ben Finney wrote: Bruno Desthuilliers writes: Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. […] Bruno, that's the first time

Re: Referring to class methods in class attributes

2010-02-17 Thread Mark Lawrence
Ben Finney wrote: Bruno Desthuilliers writes: Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. […] Bruno, that's the first time I've understood the desc

Re: Referring to class methods in class attributes

2010-02-17 Thread Ben Finney
Bruno Desthuilliers writes: > Mmmm... Let's try to explain the whole damn thing. It's really (and > IMHO beautifully) simple once you get it, but I agree it's a bit > peculiar when compared to most mainstream OO languages. […] Bruno, that's the first time I've understood the descriptor protocol,

Re: Referring to class methods in class attributes

2010-02-17 Thread Bruno Desthuilliers
John Posner a écrit : > On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: >> > Very nice writeup, Bruno -- thanks! > > >> >> >> def __call__(self, *args, **kw): >> # XXX : all sanity checks removed for readability >> if self.im_self: >> args = (self.im_func,

Re: Referring to class methods in class attributes

2010-02-17 Thread Arnaud Delobelle
Bruno Desthuilliers writes: [...] > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) > > > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The > answer is : attribute lookup rules and the descriptor pro

Re: Referring to class methods in class attributes

2010-02-17 Thread John Posner
On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. Very nice writeup, Bruno -- thanks! class method(ob

Re: Referring to class methods in class attributes

2010-02-17 Thread Bruno Desthuilliers
mk a écrit : > Stephen Hansen wrote: > >> You don't have to (and can't) refer to the class within the body. >> Class statements are sort of... odd. They are code which is directly >> executed, and the results are then passed into a >> metaclass/type/whatever and a class object is created. While wi

Re: Referring to class methods in class attributes

2010-02-17 Thread Jean-Michel Pichavant
mk wrote: Stephen Hansen wrote: You don't have to (and can't) refer to the class within the body. Class statements are sort of... odd. They are code which is directly executed, and the results are then passed into a metaclass/type/whatever and a class object is created. While within the clas

Re: Referring to class methods in class attributes

2010-02-17 Thread Stephen Hansen
On Wed, Feb 17, 2010 at 10:38 AM, mk wrote: > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature, bc all other functions in tagdata > have only a single argument: > Right, I should have caught that. You can make print_internal_date a

Re: Referring to class methods in class attributes

2010-02-17 Thread mk
Stephen Hansen wrote: You don't have to (and can't) refer to the class within the body. Class statements are sort of... odd. They are code which is directly executed, and the results are then passed into a metaclass/type/whatever and a class object is created. While within the class body, the

Re: Referring to class methods in class attributes

2010-02-17 Thread Stephen Hansen
On Wed, Feb 17, 2010 at 9:38 AM, mk wrote: > It works. But if I'd like to def print_internal_date in PYFileInfo body > like so: > > class PYFileInfo(FileInfo): >'python file properties' > >def print_internal_date(self, filename): >f = open(filename + 'c', "rb") >data = f.r