>> Hello,
>>
>> I recently changed from Python 2.5 to Python 3.0 rc2, and have
>> been trying to find out how to convert byte strings (b"example")
>> to unicode strings ("example"). I noticed that some of these had
>> changed in the latest version.
>>
>> One reason for a conversion between the two is the urllib.request.urlopen()
>> feature, which requires the string to be unicode rather than bytes, or else
>> you would receive an AttributeError error about 'bytes' object having no
>> attribute 'timeout'. The read() attribute of the urllib.request.urlopen()
>> function returns a byte string, which means I can't parse for information
>> in the bytes string to use in a second urllib.request.urlopen() function
>> unless
>> it was to be converted to unicode first.
>>
>> Am I simply overlooking something, or is there a built in function for
>> converting bytes to unicode? It seems like a function could be created
>> pretty easily if it has already not, but there isn't much sense in
>> reinventing the wheel if the function is already there.
>>
>> Thanks for your help.
>
>Already exists. Has for quite a while now:
>
>the_unicode = unicode(some_bytes, "name of encoding")
>
>Cheers,
>Chris
>--
>Follow the path of the Iguana...
>http://rebertia.com
I know that it had worked in the version 2.5, Python 3.0 rc2 doesn't
seem to recognize it as a function.
Python 3.0rc2 (r30rc2:67141, Nov 7 2008, 11:43:46) [MSC v.1500 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'unicode' is not defined
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com