How do I successfully import something from a module which has the same name as a reserved function or keyword in Python?

Viewed 68

in Python, I am trying to import the open function object from the built-in os module, but it would not let me import it as it has the same name as the built-in open function, which is used for opening files. How do I import an object/attribute from a module which uses the same name as a reserved built-in function/keyword?

Like

from os import open
2 Answers

You can alias it using as.

from os import open as osopen

you can import as another name by as

Related