[Python-Dev] Import by filename with import ? (original) (raw)

Christian Heimes lists at cheimes.de
Wed Jan 9 06:09:05 CET 2008


Today I stumbled about an unknown and undocumented (?) feature. At least it's not documented in our docs. import can import a module by file name:

open("/tmp/example.py", "w").write("test = 23\n") mod = import("/tmp/example") mod <module '/tmp/example' from '/tmp/example.py'> mod.name '/tmp/example' mod.file '/tmp/example.py' mod.test 23

Is it just a coincidence? Is it a desired feature? Why isn't it documented?

Christian



More information about the Python-Dev mailing list