importing a module by physical file path
Project description
Importing a module from physical file path.
examples
these files are existed, then..
$ tree
.
├── a
│ └── b
│ └── c
│ └── foo.py
└── main.py
4 directories, 3 files
a/b/c/foo.py
name = "foo"
_age = "*secret*"
from magicalimport import import_by_physical_path
# importing foo.py as the module named foo2
foo = import_by_physical_path("./a/b/c/foo.py", as_="foo2")
print(foo.name)
# cached by sys.modules, so it is ok.
import foo2
print(foo2.name)
star import
from magicalimport import import_by_physical_path
from magicalimport import expose_all_members
# something of like a `from foo import *`
expose_all_members(import_by_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_all_members(import_by_physical_path("./a/b/c/foo.py"), members=["_age"])
print(_age) # "*secret*"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
magicalimport-0.0.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for magicalimport-0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f455920ca001d6f2531273866f4219e4c0659ab45a9c2e438f2db308f2614a5 |
|
MD5 | 05a43f0c2416d4cdfeb81813a315d68c |
|
BLAKE2b-256 | 7597d5fedb4e9a68f670ac68fe7830f6c71c1d736529e01ecd1a1ebde37a6419 |