Safe to import __builtin__ ?

Steven D'Aprano steve at
Wed Jun 3 18:54:30 EDT 2009

On Wed, 03 Jun 2009 18:57:29 +0000, Benjamin Peterson wrote:

> mrstevegross <mrstevegross <at>> writes:
>> Is it generally safe to explicitly import __builtin__ in python? That
>> is, my code reads like this:
> ...
>> It seems like it should be a safe import, but I just want to make sure.
> Yes, that's fine. I'm not sure why you don't just use type(), though.

I'm not sure why you think type() is a substitute for __builtin__. Here's 
a typical use-case for __builtin__:

import __builtin__
def map(*args):  # shadow a built-in
    # pre-processing goes here
    result =*args)
    # post-processing goes here
    return result

How does type() help you?


More information about the Python-list mailing list