importing a module by physical file path
Importing a module from physical file path.
these files are existed, then..
$ tree . ├── a │ └── b │ └── c │ └── foo.py └── main.py 4 directories, 3 files
name = "foo" _age = "*secret*"
from magicalimport import import_from_physical_path # importing foo.py as the module named foo2 foo = import_from_physical_path("./a/b/c/foo.py", as_="foo2") print(foo.name) # cached in sys.modules, so it is ok. import foo2 print(foo2.name)
from magicalimport import import_from_physical_path import_from_physical_path("bar.py", here="/tmp/foo", as_="bar")
from magicalimport import import_from_physical_path from magicalimport import expose_all_members # something of like a `from foo import *` expose_all_members(import_from_physical_path("./a/b/c/foo.py")) print(name) # "foo" # print(_age) # NameError.. because expose_all_members() doesn't expose the symbols started by "_" # or from magicalimport import expose_members expose_members(import_from_physical_path("./a/b/c/foo.py"), members=["_age"]) print(_age) # "*secret*"
- import_module() and import_symbol()’s cwd is True
- revert default behaviour (detail https://github.com/podhmo/magicalimport/pull/18 )
- cwd option
- default behaviour is changed, from now, if here option is omitted, treated as here=__file__ on caller module.
- ( previous behaviour is here=os.getcwd() )
- skip needless __init__.py creation, in some cases
- fix directly import module handling is not enough, now, treated as a same module
- fix permission error, and same file, treated as a same module
- fix same file, treated as a same module
- fix module_id is not stored in sys.modules, on exec_module()
- raised exception adjustment
- ns option in import_symbol
- here option is supported
- python2 support
- first release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for magicalimport-0.9.1-py2.py3-none-any.whl