String adding.
Huaiyu Zhu
hzhu at users.sourceforge.net
Wed Oct 18 15:21:05 EDT 2000
On Wed, 18 Oct 2000 11:03:11 +0100, Jon Ribbens
<jon+python-list at unequivocal.co.uk> wrote:
>Alex Martelli <aleaxit at yahoo.com> wrote:
>> > BTW `x` is the same as repr(x)
>>
>> Exactly because of this, I would suggest
>> "<%s>" % whatever
>> as a preferable solution to
>> '<' + `whatever` + '>'
>
>Yes, this is one of the things that confuses me in Python. I can't see
>repr ever being used in real programs. Why is there a syntactic shortcut
>for it? Surely 'str' is almost always what you actually want?
repr is suppose to contain information to reconstruct the object.
For example
>>> from Numeric import *
>>> a = arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> print a
[0 1 2 3 4]
Say if you want to write something onto a text file and later eval it back,
you would want to use repr.
>>> b = `a`
>>> b
'array([0, 1, 2, 3, 4])'
>>> eval(b)
array([0, 1, 2, 3, 4])
>>> print eval(b)
[0 1 2 3 4]
Huaiyu
More information about the Python-list
mailing list