Open and import relatively
Project description
do-relative
Open and import relatively.
Open files relative to the module you are in, instead of __main__ module.
Import modules relatively, directly using import module syntax, without using the from . syntax.
Or use from . even if you are not in a package.
Import relative to given custom paths, including root directory so you can do an absolute import.
Installation
pip install do-relative
Api Reference
class do_relative.RelativeOpener()
Constructor of this class returns an open function, instead of its instance.
The paths you give to this function will be treated as relative to the directory calling module resides in.
do_relative.relative_import(import_statement, folder = None)
Executes the import_statement in caller's scope and relative to the calling module's location. Calling this function from another function is not supported. In that case, no new names will be introduced to caller's scope. import_statement must be a string. Examples: "import module", "from module import func" or "from .. import module". As a side note, you don't have to be in a package to use the syntax shown in the last example. If supplied, folder must be a path string. If folder is provided import will be relative to that path instead of calling module's location. folder can either be relative to current working directory or absolute. You can pass "/" as the folder and make an absolute import. On windows "/" will be converted to the root directory of some drive. Drive is determined by the current working directory.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file do_relative-1.0.0.tar.gz.
File metadata
- Download URL: do_relative-1.0.0.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19b3bf35442105d89df8fd7bc73c12655a940fdcf95f5dd2da9319aa476b3832
|
|
| MD5 |
c78e99a64a9512da48ff76bbd780d560
|
|
| BLAKE2b-256 |
834ef018783c0b1ea3497677babf78f54bbaf1cb3f922404f703281648a95307
|
File details
Details for the file do_relative-1.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: do_relative-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51c54d098a79edfe736719db1a86add751a15bc8ba3a491bace29e4f4fc24114
|
|
| MD5 |
299331f4a27324e94495970969b51f63
|
|
| BLAKE2b-256 |
de81579cc38d9306783407e7924cccd02895587e12171611f12485428bd56dca
|