Skip to main content

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.
使用作用域,以避免意外情况。

example_1.py

from force_relative_import import enable_force_relative_import

with enable_force_relative_import():
    from .moduleA import return_good

print(return_good())

example_4.py

from force_relative_import import enable_force_relative_import

with enable_force_relative_import():
    from ..moduleA import return_good

print(return_good())

example_5.py

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.
使用函数。

example_2.py

from force_relative_import import enable_force_relative_import, global_enable_force_relative_import, global_disable_force_relative_import

global_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.
仅建议用于主程序,不要用于模块或包。

example_3.py

from force_relative_import import enable_now

from .moduleA import return_good

print(return_good())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

force-relative-import-0.0.3.post0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file force-relative-import-0.0.3.post0.tar.gz.

File metadata

File hashes

Hashes for force-relative-import-0.0.3.post0.tar.gz
Algorithm Hash digest
SHA256 0dd02e9c3298301d3bab7e6a5a3dfea307001a80660fd03402a95b233965e42d
MD5 935c93024e964d193df19cbc50bde862
BLAKE2b-256 5cc29d3e530d75cdf1f1148c3b407b4832ba276040c6cbe4120720cc0f5ac0f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page