About 35,300,000 results
Open links in new tab
  1. python - How to reliably open a file in the same directory as the ...

    101 On Python 3.4, the pathlib module was added, and the following code will reliably open a file in the same directory as the current script:

  2. python - How do I check whether a file exists without exceptions ...

    How do I check whether a file exists, using Python, without using a try statement? Now available since Python 3.4, import and instantiate a Path object with the file name, and check the is_file method …

  3. python - what does the __file__ variable mean/do? - Stack Overflow

    Feb 14, 2012 · As of Python 3.4 there has been a slight change in how the __file__ behaves: It's set to the relative path of the module in which it's used, if that module is executed directly. It's set to the …

  4. python - How do I list all files of a directory? - Stack Overflow

    Jul 9, 2010 · How can I list all files of a directory in Python and add them to a list?

  5. python - Difference between modes a, a+, w, w+, and r+ in built-in …

    In Python's built-in open function, what is the difference between the modes w, a, w+, a+, and r+? The documentation implies that these all allow writing to the file, and says that they open the fi...

  6. python - Importing files from different folder - Stack Overflow

    I have this folder structure: application ├── app │ └── folder │ └── file.py └── app2 └── some_folder └── some_file.py How can I import a function from file.py, from within som...

  7. How to execute a file within the Python interpreter?

    Nov 6, 2023 · I'm trying to execute a file with Python commands from within the interpreter. I'm trying to use variables and settings from that file, not to invoke a separate process.

  8. How should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · In this case, it feels especially bad because iterators relate in a quasi-functional, value-based way to the contents of a file, but managing file handles is a completely separate task. …

  9. python - How do I get the full path of the current file's directory ...

    The above answer assumes the most common scenario of running a python script that is in a file. References pathlib in the python documentation. os.path - Python 2.7, os.path - Python 3 os.getcwd …

  10. python - What is __init__.py for? - Stack Overflow

    Here's the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A …