Skip to main content

Current module relative paths and imports

Project description

Latest PyPI Version License Supported Python Versions Format

Get the path of a file relative to the current module. Import a Python module relative to the current module. Temporarily change sys.path for imports. Get the path of a file relative to the module of the current caller.

Installation

This package runs under Python 2.7 and 3.5+, use pip to install:

$ pip install current

Usage

Get paths relative to the current module:

>>> import current

>>> here = current.current_path()
>>> parent = current.current_path('..')
>>> bruces = current.current_path('..', 'australia', 'bruces', 'bruces.ini')

Temporarily add the parent directory to sys.path:

>>> with current.inserted_path()
...     import australia

Get paths relative to the module of the callers of the current code:

>>> caller = current.caller_path()
>>> callercaller = current.caller_path(steps=2)

Potential issues

This package uses sys._getframe (which is almost the same as inspect.currentframe, see docs). Under IronPython this might require enabling the FullFrames option of the interpreter.

License

CC0 1.0 Public Domain Dedication

Changelog

Version 0.3.5: Drop Python 3.4 support.

Version 0.3.4: Tag Python 3.7 support.

Version 0.3.3: Drop Python 3.3 support. Add python_requires.

Version 0.3.2: Port tests from nose/unittest to pytest. Update meta data, tag Python 3.5/3.6 support.

Version 0.3.1: Added wheel.

Version 0.3: Added Python 3.3+ support.

Version 0.2.1: Fixed caller_path. Documented sys._getframe dependency.

Version 0.2: Added caller_path.

Version 0.1: First public release.

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

current-0.3.5.zip (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

current-0.3.5-py2.py3-none-any.whl (3.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file current-0.3.5.zip.

File metadata

  • Download URL: current-0.3.5.zip
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for current-0.3.5.zip
Algorithm Hash digest
SHA256 f368b2ed59271132f69ed5ca8490118ce891b722e85bec56e2aacf832d257fcd
MD5 0f7c0c8dfe497c0718af7c451fe6daf8
BLAKE2b-256 b0a97349de4cdfe8f3f4ff5aeb52ba4ee28354c7837971db05b9b4e492dd1370

See more details on using hashes here.

File details

Details for the file current-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: current-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for current-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 78558609f657abc43075f21bf9c001f5ae96977eae4b884c63bd2a3f62017868
MD5 7295696a545fac6928c7f0c4135b3d7f
BLAKE2b-256 b7dddd330365934062dea95d9a0ac1ddb97f82c0319b2a55254b9590fd3a518c

See more details on using hashes here.

Supported by

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