views:

159

answers:

4

Like in:

u'Hello' 

My guess is that it indicates "unicode", is it correct?

If so, since when is it available?

+6  A: 

You're right.

http://docs.python.org/tutorial/introduction.html#unicode-strings

It's been syntax since 2.0.

Stefan Kendall
+5  A: 

My guess is that it indicates "unicode", is it correct?

Yes.

If so, since when is it available?

Python 2.x.

(In Python 3.x the strings use Unicode by default and there's no need for the u prefix.)

KennyTM
+1 For the 3.x note thank you
OscarRyz
It's even a Syntax Error in Python 3 to use the `u` prefix.
Tim Pietzcker
+1  A: 

The following should help:

http://docs.python.org/library/functions.html#unicode

http://www.amk.ca/python/howto/unicode (skip down to "Python's Unicode Support" if you're already familiar with Unicode principles)

http://diveintopython.org/xml_processing/unicode.html

Brian Luft
A: 

All strings meant for humans should use u"".

I found that the following mindset helps a lot when dealing with Python string. All python manifest strings should use u"" syntax, the "" syntax is for byte arrays, only.

Before the bashing begins, let me explain. Most Python programs start out with using "" for strings. But then they need to support docs off the internet so they start using "".decode and all of a sudden they are getting exceptions everywhere about decoding this and that - all because of the use of "" for strings. In this case, Unicode does act like a virus and will wreak havoc.

But, if you follow my rule, you won't have this infection (because you will already be infected).

Frank Krueger
`bash -c "echo Shouldn\\'t you use b\\\"...\\\" for byte arrays?"`
KennyTM
@KennyTM Sounds good! Simply meant to say all strings meant for humans should use `u""`.
Frank Krueger