possibly a dumb question
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Sun Jun 30 16:01:12 EDT 2002
Adonis <deltapigz at telocity.com> wrote:
>sure:
>
>class foo:
> def __init__(self, value):
> return value
>x = foo(0)
>print x ;yeilds 0
>
>i know the code provided is wrong, but its the general idea.
>
Is this what you want?
>>> class foo:
... def __init__(self, value):
... self.value = value
... def __call__(self):
... return self.value
...
>>> x = foo(0)
>>> print x()+3
3
If you only want string representations instead of the original value
object, you can use __str__ as others have pointed out.
Huaiyu
More information about the Python-list
mailing list