Object type check

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Feb 9 08:11:47 EST 2007


On Thu, 08 Feb 2007 03:00:39 -0800, king kikapu wrote:

>> def modify(list_of_x):
>>     for x in list_of_x:
>>         try:
>>             x.change_in_place  # don't call the method, just check it exists
> 
> XXmmmm...what exactly is going on here ? I mean, what is actually
> happens if you omit the parenethesis as you just did ? I understand
> that it does not call the method, but what is really doing ??

The same as for any attribute: x.name gives the object referred to by the
attribute name, and x.name() calls that object.

He's a simple example:

>>> def foo():
...     return "foo"
...
>>> type(foo)  # the name alone
<type 'function'>
>>> type(foo())  # call the function
<type 'str'>


-- 
Steven.




More information about the Python-list mailing list