Skip to main content

add parent/ancestor folder path into sys.path when import

Project description

Given an equivalent way to achieve this but in import style, prevent formatter smash up your code

import xxx
if __name__=="__main__":
    import os,sys
    fa = os.path.abspath("/".join([sys.argv[0] + "/.."] + [".."] * 2))
    sys.path.append(fa)

import xxx_local_package # similar to ..xxx

For short, this project does this:

use this project equivalent code
import importfa.f os.path.append(sys.argv[0] + "/../..")
import importfa.ff os.path.append(sys.argv[0] + "/../../..")
import importfa.fff os.path.append(sys.argv[0] + "/../../../..")
import importfa.fffff os.path.append(sys.argv[0] + "/../../../../..")

For convenience, import importfa.f8 is equivalent to importfa.ffffffff,etc.

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

importfa-0.5.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

importfa-0.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file importfa-0.5.tar.gz.

File metadata

  • Download URL: importfa-0.5.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for importfa-0.5.tar.gz
Algorithm Hash digest
SHA256 fb0ee27adcdf97b55a79c611076f7adeb38ffefdd27267d5f5f2195717679ce0
MD5 f567cc1626d3204363200cb4b90266a0
BLAKE2b-256 ce41ebf7530738bf2fdf2e5ef64e086c2236d1fc5721c5c03a99287e473f1d90

See more details on using hashes here.

File details

Details for the file importfa-0.5-py3-none-any.whl.

File metadata

  • Download URL: importfa-0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for importfa-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 adba7b0527b19458578a23bccca996e14b37dd7d7d48cc8ae7afb2c79ed12ca7
MD5 ffb5b643ffe4a44793acb2565b508e00
BLAKE2b-256 98f08770295188e1361a5befa2c4cb0f4c9c9557250e60b40d737a337ba6d997

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