About 1,760,000 results
Open links in new tab
  1. Open file in a relative location in Python - Stack Overflow

    Aug 24, 2011 · If you are sure the file you want is in a subdirectory beneath where the script is actually located, you can use __file__ to help you out here. __file__ is the full path to where …

  2. File and directory Paths - Python Cheatsheet

    There are two main modules in Python that deal with path manipulation. One is the os.path module and the other is the pathlib module. The `pathlib` module was added in Python 3.4, …

  3. Find path to the given file using Python - GeeksforGeeks

    Aug 2, 2024 · We can get the location (path) of the running script file .py with __file__. __file__ is useful for reading other files and it gives the current location of the running file. It differs in …

  4. Working With Files in Python

    In this tutorial, you'll learn how you can work with files in Python by using built-in modules to perform practical tasks that involve groups of files, like renaming them, moving them around, …

  5. Top 2 Methods to Access Files Using Relative Paths in Your

    Nov 24, 2024 · By employing os.path.dirname(__file__), you can ensure that the path to test.txt is derived from the module’s current location, making it accessible no matter from where the …

  6. Python Path: Interact with File System Using Path from pathlib

    Summary: in this tutorial, you’ll learn how to use the Python Path class from the pathlib module to interact with the file system across platforms easily and effectively. The pathlib is a built-in …

  7. How to Use Python's Pathlib (with Examples) | DataCamp

    May 22, 2024 · Luckily, in Python version 3.4, developers introduced the pathlib module to the standard library. pathlib provides an elegant solution to handling file system paths using a long …

  8. Working with File Paths in Python - CodeRivers

    Mar 17, 2025 · In Python programming, working with file paths is an essential skill. Whether you are reading data from a file, writing output to a new file, or managing a project's directory …

  9. File and Directory AccessPython 3.13.3 documentation

    File and Directory Access¶ The modules described in this chapter deal with disk files and directories. For example, there are modules for reading the properties of files, manipulating …

  10. Reading a file using a relative path in a Python project

    But there is an often used trick to build an absolute path from current script: use its __file__ special attribute: test = list(csv.reader(f)) This requires python 3.4+ (for the pathlib module). If …

Refresh