figuring out # of bytes
John J. Lee
jjl at pobox.com
Sun Apr 24 08:08:55 EDT 2005
Jaime Wyant <programmer.py at gmail.com> writes:
> On 22 Apr 2005 13:28:57 -0700, codecraig <codecraig at gmail.com> wrote:
> > i want to the number of bytes in a string...
> >
> > is, len(x) accurate?
> >
> > so, x = "hi"
> > len(x) == 2 ....so that means two bytes?
> >
> > thanks
>
> No, that means that the string is two bytes in length. The number of
> bytes is dependent on the encoding. It seems like there was a thread
[...]
That's only an issue if type(x) != str. (eg., type(x) == unicode)
John
More information about the Python-list
mailing list