Returning a string
Diez B. Roggisch
deets at nospam.web.de
Sat Jan 3 14:49:36 EST 2009
Kless schrieb:
> On 3 ene, 19:12, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>> Kless schrieb:
>>
>>> How is possible that I can print a variable, but when I use *return
>>> var* it returns an empty string
>>> http://paste.pocoo.org/show/97588/
>> I don't see anything that indicates that the returned object is the
>> empty string. Simply because there is no code testing for that. And of
>> course you don't show any debugging output, which doesn't help either.
>>
>> Diez
>
> Afghanistan
> AF
> Out[19]: u'AF'
> AFG
> Out[19]: u'AFG'
> 004
> Out[19]: u'004'
What is that? IPython? And I don't see no empty string here. *What* I
see is the way python's interactive prompt puts out strings, like this:
>>> unicode("foo")
u'foo'
Do you mean by any chance that you don't understand why print prints
foo, but the prompt shows u"foo"? That is because the prompt invokes
repr(o)
to print out an object:
>>> print repr(unicode("foo"))
u'foo'
Which means that the output includes quotes and the "u"-prefix in case
of an unicode object to help the user to see what the current object
looks like.
Diez
More information about the Python-list
mailing list