amjoconn
amjoconn

Reputation: 2203

Explicit access to Python's built in scope

How do you explicitly access name in Python's built in scope?

One situation where I ran in to this was a in module, say called foo, which happened to have an open function. In another module foo's open function would be accessible as foo.open which works well. In foo itself though, open blocks the built in open. How can you access the built in version of a name like open explicitly?

I am aware it is probably practically bad idea to block any built in name, but I am still curious to know if there is a way to explicitly access the built in scope.

Upvotes: 11

Views: 2125

Answers (2)

Chris B.
Chris B.

Reputation: 90221

Use __builtin__.

def open():
    pass

import __builtin__

print open
print __builtin__.open

... gives you ...

<function open at 0x011E8670>
<built-in function open>

Upvotes: 12

David Z
David Z

Reputation: 131599

It's something like

__builtins__.open()

Upvotes: -2

Related Questions