About 33,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 - 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 …

  3. 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 …

  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 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 - Why am I getting a FileNotFoundError? - Stack Overflow

    $ python script.py In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are …

  7. How can I delete a file or folder in Python? - Stack Overflow

    How do I delete a file or folder in Python? For Python 3, to remove the file and directory individually, use the unlink and rmdir Path object methods respectively:

  8. 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...

  9. 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 …

  10. 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.