But what if we want to encode a standard string as Unicode? While there are some who think that, when it is spoken slowly enough and loudly enough, everyone understands English. This method of communication works even less for computers than it does for humans.
As mentioned earlier, Python's default encoding is usually ASCII. It can, however, be set to other encodings. To find out which encoding a given Python installation is using, use the method sys.getdefaultencoding(). In the Python shell, it will look like this:
>>> import sys >>> sys.getdefaultencoding() 'ascii'To convert a standard, ASCII string to Unicode, we simply use Python's built-in unicode function:
t = "Hello"Now, x contains the Unicode form of t. You might ask: What's the difference? On your local system, probably none. If, however, you are a consultant programming in Missoula, Montana for a Greek-speaking client in Athens, there is a substantial difference. See the next page for a more detailed explanation.
x = unicode(t)
