Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Referencing a specific function in python by namespace?

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 ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading