About 4,860,000 results
Open links in new tab
  1. How to access a module from outside your file folder in Python?

    Nov 3, 2016 · Instead of '..' one can use os.path.pardir . So it becomes: sys.path.append(os.path.abspath(os.path.join(os.path.pardir, 'config'))) Yo can only import modules that are visible by your environment. You can check the environment using this. As you will see sys.path is a list so you can append elements to it:

  2. python code to get the files outside the current working directory

    Apr 21, 2014 · os.path.split(os.getcwd())[0] to get the parent directory. Please improve your post by explaining what you are doing and why. See stackoverflow.com/help/how-to-answer for some hints on how to write good answers. (Your answer is probably working, but you're not explaining it. Also, why insert at index 1 and not 0?)

  3. Open File in Another Directory (Python) - Stack Overflow

    Sep 9, 2015 · If you have Python 3.4 or above, the pathlib library comes with the default distribution. To use it, you just pass a path or filename into a new Path () object using forward slashes and it handles the rest.

  4. Python - Import module outside directory - GeeksforGeeks

    May 15, 2023 · If the module exists in the same directory as the file, we can directly import it using the syntax import module_name. But if it exists in a different directory we cannot directly import it.

  5. File and directory Paths - Python Cheatsheet

    There are two ways to specify a file path. There are also the dot (.) and dot-dot (..) folders. These are not real folders, but special names that can be used in a path. A single period (“dot”) for a …

  6. Python – Import module from different directory

    Jun 20, 2024 · ModuleNotFoundError, because by default Python interpreter will check for the file in the current directory only, and we need to set the file path manually to import the modules from another directory. We can do this using various ways. These ways are discussed below in detail.

  7. How to see if a file exists in parent directories with Python

    Python tests if files exists in parent directories with the parents property and Path.glob () method. This code tutorial explains with a custom function.

  8. How to Reference a Directory Outside of Your Folder in Python

    Learn how to correctly reference files in parent directories while working on Python projects. This guide provides clear steps and examples for navigating file paths in your code.

  9. Python Pathlib: File System Operations in Python - Python Central

    # Joining paths file_path = os.path.join('data', 'processed', 'results.csv') # Getting file name file_name = os.path.basename(file_path) # Checking if a file exists if os.path.exists(file_path) and os.path.isfile(file_path): # Reading a file with open(file_path, 'r') as f: content = f.read()

  10. Python Pathlib.parent Explained - PyTutorial

    Mar 23, 2025 · Python's pathlib module is a powerful tool for handling file paths. One of its most useful methods is parent. This method helps you navigate through directories by returning the …

Refresh