n is a object,what means: s='n' ?

Des Small des.small at bristol.ac.uk
Fri Aug 31 06:03:15 EDT 2001


"Formalin" <formalin14 at email.com.cn> writes:

> class now:
>     ....
>     ....
>     ....
> n=now()
> s='n'

Is this really backquotes, i.e., `n`?  If so it's syntactic sugar for 

s = repr(n)

which assigns to s the printable representation (a string) of n.  If
you're working at the command line then just

>>> n

will show this string, too.  If you want to customize the printed
representation of the object, you can define a method '__repr__' for
your class like this:

<transcript>
>>> class Foo:
...     def __repr__(self): return 'I\'m a foo!'
... 
>>> f = Foo()
>>> f
I'm a foo!
</transcript>


> print s
> 
> the result:<__main__.now instance at 00B2EB0C>
> 
> what means?????
> 

Des,
likes talking to the command line.
-- 
Dr Des Small, Scientific Programmer,
School of Mathematics, University of Bristol,
Tel: 0117 9287984



More information about the Python-list mailing list