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
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
>>
>>
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:/
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'
> >
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
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
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
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
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
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
> ...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):
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
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()
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
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
15 matches
Mail list logo