Skip to main content

Current module relative paths and imports

Project description

Latest PyPI Version License Downloads

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

$ 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.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.2.1.zip (7.3 kB view details)

Uploaded Source

File details

Details for the file current-0.2.1.zip.

File metadata

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

File hashes

Hashes for current-0.2.1.zip
Algorithm Hash digest
SHA256 3eb2baf81eed5f4510c73618dcb0b0c0f6685e401389ef81db28b96ad4b448ac
MD5 f222204782e0c7b85ef9041c947385ea
BLAKE2b-256 b7df85706bec860e0ef5bf7b64180e9f1577d04e27d9f747bf9ba0ba8474bb31

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