DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

PythonSprache > PythonDoctest > PythonEggs > PythonEvangelism > PythonExecutables > PythonExif > PythonFunctionAnnotations > PythonHacks > PythonHacking > PythonIDE > PythonIDEs > PythonIdioms > PythonImageLibrary > PythonInTheEnterprise > PythonServerPages > PythonToJavascript > PythonUnicodeClear Trail
Main /

Python Unicode

Python
Unicode
Unicode Transformation Format
Unicode is an abstract mapping from numbers to character symbols. It is not a document encoding.
UTF-8 is a document encoding.

When printing a string, Python will attempt to convert it to your default encoding, which is usually ASCII.[1]

 >>> u'üöä'
 u'\xfc\xf6\xe4'


 >>> u"Hello World!"  #create a Unicode string
 u'Hello World!'
To construct the string, Python assumed that the literal input was in UTF8, the "default encoding".[2]

Sometimes you want to see how stuff is being stored internally. We deal with this using an 'encoding' called 'utf-16', which is actually pretty close to how the Unicode is stored internally. In fact, there are two flavours, 'utf-16-le' for little-endian machines and 'utf-16-be' for big-endian machines.
 >>> a.encode('utf-16')
 '\377\376A\000n\000d\000r\000\202\000'
So utf-16 is almost like the internal representation of unicode-strings in python. The raw string so to speak.




MySQL


Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 26.07.2008 20:31 Uhr und seit 7. April 2005 854 aufgerufen.