Skip to main content

Open and import relatively

Project description

do-relative

Open and import relatively. Open files relative to the module you are in, instead of __main__ module. Import modules relatively, directly using import module syntax, without using the from . syntax. Or use from . even if you are not in a package. Import relative to given custom paths, including root directory so you can do an absolute import.

Installation

pip install do-relative

Api Reference

class do_relative.RelativeOpener()

Constructor of this class returns an open function, instead of its instance. The paths you give to this function will be treated as relative to the directory calling module resides in.

do_relative.relative_import(import_statement, folder = None)

Executes the import_statement in caller's scope and relative to the calling module's location. Calling this function from another function is not supported. In that case, no new names will be introduced to caller's scope. import_statement must be a string. Examples: "import module", "from module import func" or "from .. import module". As a side note, you don't have to be in a package to use the syntax shown in the last example. If supplied, folder must be a path string. If folder is provided import will be relative to that path instead of calling module's location. folder can either be relative to current working directory or absolute. You can pass "/" as the folder and make an absolute import. On windows "/" will be converted to the root directory of some drive. Drive is determined by the current working directory.

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

do_relative-1.0.0.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

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

do_relative-1.0.0-py2.py3-none-any.whl (2.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file do_relative-1.0.0.tar.gz.

File metadata

  • Download URL: do_relative-1.0.0.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for do_relative-1.0.0.tar.gz
Algorithm Hash digest
SHA256 19b3bf35442105d89df8fd7bc73c12655a940fdcf95f5dd2da9319aa476b3832
MD5 c78e99a64a9512da48ff76bbd780d560
BLAKE2b-256 834ef018783c0b1ea3497677babf78f54bbaf1cb3f922404f703281648a95307

See more details on using hashes here.

File details

Details for the file do_relative-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: do_relative-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for do_relative-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 51c54d098a79edfe736719db1a86add751a15bc8ba3a491bace29e4f4fc24114
MD5 299331f4a27324e94495970969b51f63
BLAKE2b-256 de81579cc38d9306783407e7924cccd02895587e12171611f12485428bd56dca

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