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 ?
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)
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 ?
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)