Referencing a specific function in python by namespace?

Question:

I included the os module into my program and now the standard file open() call is being occluded by os.open(), is there a way to reference a specific namespace ?

Asked By: John Sohn

||

Answers:

The solution: don’t do things like this:

from os import *

Instead, do this:

import os

Then, you can reference the os open function like this:

os.open(something)

And the built-in open as open(filename). If, however, something is shadowing a built-in function:

import builtins
builtins.open(filename)
Answered By: pigrammer
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.