Allow users to bypass Python relative import restrictions.
Project description
force-relative-import
This is a library that forcibly enables Python relative import, allowing you to ignore Python's relative import restrictions.
这是一个强制启用python相对导入的库,允许你忽略python的相对导入限制。
Install / 安装
pip install -U force-relative-import
Usage Method / 使用方法
Method 1 (Recommend) / 方法1 (推荐)
Use scopes to avoid unexpected situations.
使用作用域,以避免意外情况。
from force_relative_import import enable_force_relative_import
with enable_force_relative_import():
from .moduleA import return_good
print(return_good())
from force_relative_import import enable_force_relative_import
with enable_force_relative_import():
from ..moduleA import return_good
print(return_good())
from force_relative_import import enable_force_relative_import
with enable_force_relative_import():
from ...moduleA import return_good
print(return_good())
Method 2 / 方法2
Using functions.
使用函数。
from force_relative_import import enable_force_relative_import, global_enable_force_relative_import, global_disable_force_relative_import
global_enable_force_relative_import()
with enable_force_relative_import():
from .moduleA import return_good
global_disable_force_relative_import()
print(return_good())
Method 3 / 方法3
Recommended only for main programs, not for modules or packages.
仅建议用于主程序,不要用于模块或包。
from force_relative_import import enable_now
from .moduleA import return_good
print(return_good())
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
Close
Hashes for force-relative-import-0.0.1.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23efcfbfb8a0ecf86e003f26e4d45443726b43e7407c13df95ae3c28c951cb19 |
|
MD5 | 9daca719c80a2774cb60011a17ae608d |
|
BLAKE2b-256 | d9c8ab3c9be6b3994436e871d9292be31d31ee6cde8cd22e490a67397c9f8b7c |