Question on Strings

Chris Rebert clp2 at rebertia.com
Fri Feb 6 05:24:09 EST 2009


On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan
<soft_smith at yahoo.com> wrote:
>
> Hi,
>
> Excuse me if this is a repeat question!
>
> I just wanted to know how are strings represented in python?
>
> I need to know in terms of:
>
> a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters?

IIRC, Depends on what the build settings were when CPython was
compiled. UTF-16 is the default.

> b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)?

No. They are implicitly converted to ASCII in such cases. To properly
handle non-ASCII Unicode characters, you need to encode/decode the
strings to/from bytes manually by specifying the encoding.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list