About 23,100,000 results
Open links in new tab
  1. 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 …

  2. 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:

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

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

  5. How to get an absolute file path in Python - Stack Overflow

    Sep 9, 2008 · I quote the Python 3 docs for abspath: "Return a normalized absolutized version of the pathname path." Not a"...version of the string path ". A pathname, as defined by Posix, is …

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

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

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

  9. python - How do I copy a file? - Stack Overflow

    How do I copy a file in Python?copy2(src,dst) is often more useful than copyfile(src,dst) because: it allows dst to be a directory (instead of the complete target filename), in which case the …

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