About 309,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 - Pythonic way to check if a file exists? - Stack Overflow

    Feb 14, 2010 · If, on the other hand, you want to leave the file alone if it exists, but put specific non-empty contents there otherwise, then more complicated approaches based on if …

  3. How to check if a file exists in python? - Stack Overflow

    Aug 2, 2011 · I cannot recall offhand if python supports the syntax or if it will normalize long path's via the conventional format (i.e. C:\path\...) – bgura Commented May 14, 2019 at 13:15

  4. check for file existence in Python 3 - Stack Overflow

    Well, you can always open a file for writing - if it exists, it will be cleared, if it doesn't exist, it will be created. – Tim Pietzcker Commented May 4, 2014 at 17:18

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

    Aug 9, 2011 · Deleting a file or folder in Python. There are multiple ways to delete a file in Python but the best ways are the following: os.remove() removes a file. os.unlink() removes a file. It is …

  6. python - How to replace/overwrite file contents instead of …

    Neither truncate nor open(..., 'w') will change the inode number of the file (I tested twice, once with Ubuntu 12.04 NFS and once with ext4). By the way, this is not really related to Python. The …

  7. python - Writing to a new file if it doesn't exist, and appending to …

    The file is named by the user when they choose a playername. If the file with that specific username already exists, then the program should append to the file (so that you can see …

  8. How do I check if a directory exists in Python? - Stack Overflow

    Jan 19, 2012 · pathlibPath.exists() For Python 3.4. Pathlib Module is included in Python 3.4 and later versions to handle file system paths. Python checks if a folder exists using an object …

  9. Most pythonic way to delete a file which may not exist

    May 31, 2012 · As of Python 3.8, use pathlib.Path.unlink with the missing_ok=True kwarg ().. Otherwise, a try/except block is the best way to do it as it is thread-safe (unlike an if/else block …

  10. python - Use wildcard with os.path.isfile () - Stack Overflow

    Aug 23, 2021 · If you just care about whether at least one file exists and you don't want a list of the files: import glob import os def check_for_files(filepath): for filepath_object in …

Refresh