当前模块相对路径和导入
项目描述
获取当前模块的文件相对路径。从当前模块导入Python模块。临时更改sys.path以进行导入。获取相对于当前调用者模块的文件路径。
链接
安装
此包在Python 3.7+上运行,使用pip安装
$ pip install current
用法
获取相对于当前模块的路径
>>> import current
>>> here = current.current_path()
>>> parent = current.current_path('..')
>>> bruces = current.current_path('..', 'australia', 'bruces', 'bruces.ini')
临时将父目录添加到sys.path
>>> with current.inserted_path()
... import australia
获取相对于当前代码调用者模块的路径
>>> caller = current.caller_path()
>>> callercaller = current.caller_path(steps=2)
潜在问题
此包使用 sys._getframe(几乎与 inspect.currentframe 相同,见 文档)。在 IronPython 下,可能需要启用解释器的 FullFrames 选项。
许可证
变更日志
版本 0.4.1:弃用 Python 3.6 支持。
版本 0.4:弃用 Python 2 和 3.5 支持;标记 Python 3.9 和 3.10 支持。
版本 0.3.6:标记 Python 3.8 支持。扩展测试覆盖。
版本 0.3.5:弃用 Python 3.4 支持。
版本 0.3.4:标记 Python 3.7 支持。
版本 0.3.3:弃用 Python 3.3 支持。添加 python_requires。
版本 0.3.2:将测试从 nose/unittest 迁移到 pytest。更新元数据,标记 Python 3.5/3.6 支持。
版本 0.3.1:添加 wheel。
版本 0.3:添加 Python 3.3+ 支持。
版本 0.2.1:修复 caller_path。记录 sys._getframe 依赖。
版本 0.2:添加 caller_path。
版本 0.1:首次公开发布。
项目详情
下载文件
下载适合您平台的应用程序。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。
源分布
current-0.4.1.zip (13.8 kB 查看哈希值)
构建分布
current-0.4.1-py3-none-any.whl (6.2 kB 查看哈希值)
关闭
current-0.4.1.zip 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bf5ddb6669cd8cbd31247aff70cd90d52d69464cb1f2b23928a893dc940edfbd |
|
MD5 | 0a3d455ddf7c1cb1215cbf70c05aa4d0 |
|
BLAKE2b-256 | 0022e2d9bd53d9d77d01f847f95a5b985d8abd6e8229be0a739300fe48771e7f |
关闭
current-0.4.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cdbe0e044a91a9b826af5ca3168305e09f12bc0fb3a55c5a7fe338b72940e6fa |
|
MD5 | 055f399c76ccf328d9485d5972e03f43 |
|
BLAKE2b-256 | 3db0d837950186186dea77816946eedd2baa0ac0b2c1a7bbe46131cd3dea7589 |