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
            
        
        
            Active
            
        
            Viewed 20 times
        
    1
            
            
        - 
                    4Do `import os` (which leaves `os` as its own namespace) instead of `from os import *` . `import *` is bad for exactly this reason. – Samwise Aug 27 '22 at 22:08
- 
                    2Less-good answer is to use `builtins.open`. – Samwise Aug 27 '22 at 22:09
- 
                    I like both because both answer my question. – John Sohn Aug 27 '22 at 22:10
- 
                    2Even worse answer is `del open`. – Mateen Ulhaq Aug 27 '22 at 22:10
1 Answers
2
            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)
 
    
    
        pigrammer
        
- 2,603
- 1
- 11
- 24
