跳转到主要内容

当前模块相对路径和导入

项目描述

Latest PyPI Version License Supported Python Versions Wheel format

Build Codecov

获取当前模块的文件相对路径。从当前模块导入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 选项。

许可证

CC0 1.0 通用

变更日志

版本 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 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面