Re: functions, classes, bound, unbound?

2007-03-26 Thread 7stud
On Mar 26, 6:49 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > > class Test(object): > pass > def greet(x): > print "hello" > Test.func = greet > print Test.func > t = Test() > print t.func > def sayBye(x): > print "bye" > t.bye = sayBye > print t.bye

Re: functions, classes, bound, unbound?

2007-03-26 Thread Bruno Desthuilliers
7stud a écrit : > On Mar 25, 3:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > >>Here's another way of looking at it:: >> >> >>> class Test(object): >> ... pass >> ... >> >>> def greet(): >> ... print 'Hello' >> ... >> Test.greet = greet Test.greet >> >>

Re: functions, classes, bound, unbound?

2007-03-26 Thread 7stud
On Mar 26, 5:08 am, Bruno Desthuilliers wrote: > Most of Python's object model is documented here: > > http://www.python.org/download/releases/2.2.3/descrintro/http://users.rcn.com/python/download/Descriptor.htm > Thanks. I've looked at both of those, and the second one is very good. -- http:/

Re: functions, classes, bound, unbound?

2007-03-26 Thread irstas
On Mar 26, 7:15 pm, "7stud" <[EMAIL PROTECTED]> wrote: > On Mar 25, 3:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > > > Here's another way of looking at it:: > > > >>> class Test(object): > > ... pass > > ... > > >>> def greet(): > > ... print 'Hello' > >

Re: functions, classes, bound, unbound?

2007-03-26 Thread 7stud
On Mar 25, 3:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > Here's another way of looking at it:: > > >>> class Test(object): > ... pass > ... > >>> def greet(): > ... print 'Hello' > ... >>> Test.greet = greet >>> Test.greet > Interesting. After playi

Re: functions, classes, bound, unbound?

2007-03-26 Thread Bruno Desthuilliers
7stud a écrit : >> ...classes don't invoke the function directly, they convert it to >> an 'unbound method' object:: (snip) > >> If you really want to get to the original function, there are a couple >> of options. > > No. Just trying to figure out how some things work. Most of Python's objec

Re: functions, classes, bound, unbound?

2007-03-25 Thread Steven Bethard
On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > Is there some other way to retrieve a user-defined function object > from a class other than using the class name or an instance? On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: > What Steven B. already said, MyClass.__dict__['someFunc'], is

Re: functions, classes, bound, unbound?

2007-03-25 Thread 7stud
On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: > On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > > > MyClass.someFunc > > > Is there some other way to retrieve a user-defined function object > > from a class other than using the class name or an instance? > > What Steven B. already said, MyC

Re: functions, classes, bound, unbound?

2007-03-25 Thread Gabriel Genellina
En Sun, 25 Mar 2007 17:22:36 -0300, 7stud <[EMAIL PROTECTED]> escribió: > On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: >> On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: >> >> > Is there some other way to retrieve a user-defined function object >> > from a class other than using the class

Re: functions, classes, bound, unbound?

2007-03-25 Thread irstas
On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > MyClass.someFunc > > Is there some other way to retrieve a user-defined function object > from a class other than using the class name or an instance? What Steven B. already said, MyClass.__dict__['someFunc'], is a different way than MyClass

Re: functions, classes, bound, unbound?

2007-03-24 Thread 7stud
> ...classes don't invoke the function directly, they convert it to > an 'unbound method' object:: > > >>> class Test(object): > ... def greet(): > ... print 'Hello' > ... > >>> Test.greet > > >>> Test.greet() > Traceback (most recent call last):

Re: functions, classes, bound, unbound?

2007-03-24 Thread Steven Bethard
7stud wrote: > Here is some example code that produces an error: > > class Test(object): > def greet(): > print "Hello" > > t = Test() > t.greet() > TypeError: greet() takes no arguments (1 given) [snip] > Test.greet() > > TypeError: unbound method greet() must be called

Re: functions, classes, bound, unbound?

2007-03-24 Thread Steven D'Aprano
On Sat, 24 Mar 2007 20:24:36 -0700, 7stud wrote: > Here is some example code that produces an error: > > class Test(object): > def greet(): > print "Hello" > > t = Test() > t.greet() > TypeError: greet() takes no arguments (1 given) > > Ok. That makes sense. t.greet()

Re: functions, classes, bound, unbound?

2007-03-24 Thread Felipe Almeida Lessa
On 24 Mar 2007 20:24:36 -0700, 7stud <[EMAIL PROTECTED]> wrote: > Here is some example code that produces an error: [snip] Why do people absolutely *love* to do weird and ugly things with Python? Contests apart, I don't see lots of people trying this kind of things on other (common) languages. Sa

functions, classes, bound, unbound?

2007-03-24 Thread 7stud
Here is some example code that produces an error: class Test(object): def greet(): print "Hello" t = Test() t.greet() TypeError: greet() takes no arguments (1 given) Ok. That makes sense. t.greet() is a "bound method", so something automatically relays the instance obje