Skip to main content

current_path

badge

current_path is a small library for getting current path data for a script that imports this library.

Installation

pip install current-path

Usage

Get the current file's path which imports current-path:

from current_path import current_file

if __name__ == '__main__':
    print(current_file())

Get the current directory's path which contains the file which imports current-path:

from current_path import current_dir

if __name__ == '__main__':
    print(current_dir())

Temporarily change the current working directory to the file's directory until the code block under the context manager has been completed:

from current_path import current_dir_as_cwd
import os


def create_file(path: str):
    with open(path, 'w'):
        """File has been created."""

        
if __name__ == '__main__':
    #  CWD is some arbitrary directory.
    
    with current_dir_as_cwd():
        #  CWD is this file's directory.
        os.mkdir("file_directory")
        create_file("file_0.txt")
    
    #  CWD returns to same arbitrary directory.

The above code ensures that, no matter which working directory the script is invoked from, the file is created in the same location.

License

Licensed under the CC0 License.

Metadata

Release files for current-path 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for current-path 0.0.4
File Size Uploaded Provenance Actions
current-path-0.0.4.tar.gz 5.7 kB Without provenance Details for current-path-0.0.4.tar.gz

Release files / current-path-0.0.4.tar.gz

Download URL current-path-0.0.4.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5de08b9591c5819fbecdaab9476b55bfd96b04adbc8d58870fe14d3f1e86dd28
BLAKE2b-256 checksum
How to use checksums
1c9104ff6bc165d3cfdc3b40ed8d07cafc54447b34cb4a0983d98d4af082d656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Security for current-path 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page