Skip to main content

Change working directory up a number of levels or to a named folder

Project description

ezdir

Simple utilities to change the current working directory in Python:

  • up(n) changes working folder to be up n directory levels.
  • goto("foldername") changes working folder to the first parent folder (within the original path) matching a name.
  • find("foldername") changes working folder to the first parent folder matching a name under n directory levels.

Examples

If your current file is Users/me/MyWork/src/main/work[.py/.ipynb] and you wanted to go up one level to src you could use the up function:

import ezdir

ezdir.up(levels=1)

If you wanted to go to Users/me/MyWork/src you could go up two levels or use the goto function:

import ezdir

ezdir.trim(folder_name='src')

As the src folder is within the original path.

If you wanted to switch your working directory to Users/me/MyWork/tests you could use find:

import ezdir

ezdir.find(levels=2, folder_name='tests')

As this will go up two levels, and then search for a tests folder. We include a number of excluded folders (e.g. build), but you can exclude more folders by passing a list to the ezdir.find as the add_ignore_subfolders variable.

Installation

pip install ezdir

Why use it?

Changing working directory in a Jupyter Notebook

If you are using a notebook on a cloud server, your working directory might be different to some elses. Normally people do something like:

import os

os.chdir(path)

But sometimes this path will be different based on the user. This library provides a more sensible way of going up folder paths whether you're using a python script or a notebook.

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

ezdir-0.3.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

ezdir-0.3.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ezdir-0.3.0.tar.gz.

File metadata

  • Download URL: ezdir-0.3.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.16

File hashes

Hashes for ezdir-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8ff95bfc43432e11add622001933d1c3fb2c509fa46f697ea5e612269db31f48
MD5 f96ee84d171c1cf55470ea393c11212c
BLAKE2b-256 3a17d9493c41e9c3ea57de2700a8ca0c6efd9a04aded197ab7a0e4a5f43f3463

See more details on using hashes here.

File details

Details for the file ezdir-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ezdir-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.16

File hashes

Hashes for ezdir-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4c57c6d64fbecbf5067def8254aab036ed92a2c251d18a8c5809a8c36380764
MD5 332d24d4360ac6064930fe0667405ab6
BLAKE2b-256 161bc807ec49d594e5d4c1d21c141806971e66eaf3a7388964a56239c53475bc

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