[Python-Dev] Initialization of __builtins__

Antoine Pitrou solipsis at pitrou.net
Sat Oct 10 21:40:34 CEST 2009


Vinay Sajip <vinay_sajip <at> yahoo.co.uk> writes:
> 
> In the py3k branch, logging has the line
> 
> _unicode = 'unicode' in dir(__builtins__)

Why do you do this?
In py3k, unicode is always enabled but it's called "str" and the name "unicode"
doesn't exist.

> to determine the existence of Unicode support. The code in trunk, being 1.5.2
> compatible, used
> 
> hasattr(types, 'UnicodeType')

Why don't you simply write:

    unicode_support = True
    try:
        unicode
    except NameError:
        unicode_support = False

?




More information about the Python-Dev mailing list