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_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)
here option
from magicalimport import import_from_physical_path
import_from_physical_path("bar.py", here="/tmp/foo", as_="bar")
star import
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*"
0.3
ns option in import_symbol
0.2.1
here option is supported
0.2
python2 support
0.1
first release
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.3.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for magicalimport-0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d69796cf61c7d2bfb35c7e7e03dfd8c21db850e18ac38a26c6545f9d5c121367 |
|
MD5 | 129a1d0a601c2d2a5c9367638ccf3e64 |
|
BLAKE2b-256 | 92c233287241181564abfcea6c33083aca74e637cc38f5702d8f022c564590fa |