[Python-Dev] The Breaking of distutils and PyPI for Python 3000?
"Martin v. Löwis"
martin at v.loewis.de
Thu Mar 20 23:07:43 CET 2008
>> if type(response) in (str, str):
>
> Then I'm taking him too literally, when he writes that the tool won't
> touch *anything* that has to do with the str->bytes/unicode->str move (I
> assumed that meant it wouldn't touch "unicode" in the snippet I gave
> above), right?
It definitely replaces unicode->str in this fragment.
> Will the tool also make the following work correctly?
>
> if type(s) is str: s = unicode(s, 'utf-8')
It outputs
if type(s) is str: s = str(s, 'utf-8')
This is probably not correct. However, in 2.6, you could write
that as
if type(s) is bytes: s = unicode(s, 'utf-8')
as bytes is str in 2.6. If you want to support even older
versions, do
try:
bytes
except NameError:
bytes = str
somewhere, then write the code as I proposed above.
Regards,
Martin
More information about the Python-Dev
mailing list