Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit access to Python's built in scope

Tags:

python

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.

like image 310
amjoconn Avatar asked Jun 04 '09 20:06

amjoconn


1 Answers

Use __builtin__.

def open():
    pass

import __builtin__

print open
print __builtin__.open

... gives you ...

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

like image 117
Chris B. Avatar answered Oct 25 '22 12:10

Chris B.