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.3+, 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.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.1.zip (7.7 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.1-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file current-0.3.1.zip.

File metadata

  • Download URL: current-0.3.1.zip
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for current-0.3.1.zip
Algorithm Hash digest
SHA256 207613dc19a6cc8e1a756f26e416733c8f82a70e4ae81103d22f483aae6492a8
MD5 6378769c64d76831e72a6930b47ced27
BLAKE2b-256 7fc8bccb923ccbcde64527baa29cfc4c6d1235970e4fd01afbd5dde1bf01b7b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for current-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b1e2ddabd3de44be215b66abc840061787d9e82a6f1d332e3cf23786652f12a
MD5 2324f9c1c2f2ffc4682267aa057af414
BLAKE2b-256 79c340a7568d3ab53b70d40b5a169b425932b8c84dd6244d5ede629a329fa322

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