Newbie question

Huaiyu Zhu hzhu at users.sourceforge.net
Fri Sep 8 17:11:58 EDT 2000


On Fri, 08 Sep 2000 18:13:22 GMT, cherokee30114 at my-deja.com
<cherokee30114 at my-deja.com> wrote: 
>myarg = repr(mytup[0])
>>>> print myarg
>'A'
>>>> if myarg == 'A':
>... 	print "ok"
>... else:
>... 	print "bad"
>...
>bad

str gives you the content of a string.  repr gives you a representation of a
string as in program.

This is what you want
>>> s='A'
>>> s=='A'
1
>>> print s
A
>>> print `s`
'A'
>>> s 
'A'
>>> `s`
"'A'"

This is what you did (note that `s` is equivalent to repr(s)).
>>> s=`s`
>>> s=='A'
0
>>> s=="'A'"
1
>>> len(s)
3
>>> print s
'A'
>>> print `s`
"'A'"
>>> s
"'A'"
>>> print `s`
"'A'"
>>> `s`
'"\'A\'"'




More information about the Python-list mailing list