constructor question
TeroV
teroV at nowhere.invalid
Mon Jan 21 18:10:05 EST 2008
azrael wrote:
> lets supose i have a object
>
>>>> class a:
>>>> __init__(self,b):
>>>> self.b=b
>
>>>> object=a(2)
>
>
> how can I bind the object with "print". I supose that this should be
> possible with a constructor. but I don't know how.
>
>>>> print a
> 2
>
> Something like this
>
>
> Thnx
Is it that you want to print an object, and customize what is printed?
__str__ method is what you need, see
http://docs.python.org/ref/customization.html
--
Tero
More information about the Python-list
mailing list