Objects in Python
Peter Otten
__peter__ at web.de
Wed Aug 22 10:36:00 EDT 2012
shaun wrote:
> I'm having an issue its my first time using python and i set up a class
> one of the methods is supposed to return a string but instead returns:
>
> <bound method Param.returnString of <Param.Param instance at 0x00C
> 389E0>>
>
> Im very new to python and the object orientated feature doesnt seem to be
> as well put together as Java.
It's definitely too early for you to draw conclusions ;)
> Can anyone help with this problem?
You have successfully created a bound method, now you need to invoke it:
>>> class Param(object):
... def returnString(self):
... return "hello"
...
>>> p = Param()
>>> p.returnString
<bound method Param.returnString of <__main__.Param object at
0x7facb3a16a50>>
>>> p.returnString()
'hello'
Unlike some other langages Python does not implicitly invoke functions or
methods. That makes it easy to pass them around like any other object.
More information about the Python-list
mailing list