About 1,900,000 results
Open links in new tab
  1. python - How to handle FileNotFoundError when "try .. except …

    unrelated: do not use the same name for different purposes in the same context. Use text = file.read() instead. Keep the text as Unicode, do not encode it to bytes unless it is absolutely necessary. –

  2. What is a good way to handle exceptions when trying to read a …

    I want to read a .csv file in python. I don't know if the file exists. My current solution is below. It feels sloppy to me because the two separate exception tests are awkwardly juxtaposed. Is th...

  3. python - Why am I getting a FileNotFoundError? - Stack Overflow

    That way, you can simply cd to the directory containing your Python script file and run it. In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or …

  4. Python FileNotFound - Stack Overflow

    Mar 13, 2014 · I am fairly new to python. I am trying to make a script that will read sudoku solutions and determent if they are correct or not. Things I need: 1] Prompt the user to enter a file/file path which

  5. Catching an exception while using a Python 'with' statement

    I can't figure out how to handle exception for python 'with' statement. If I have a code: with open("a.txt") as f: print f.readlines() I really want to handle 'file not found exception' in order to do something. But I can't write. with open("a.txt") as f: print …

  6. File not found from Python although file exists - Stack Overflow

    Apr 24, 2018 · I have full access to the file. I've created it and it has been working until a few hours ago. I'm under Windows, but I've checked the file properties and I indeed have full permission to the file. Moreover, the problem really is that Python does not "see" the file even though it lists it (see last edit). So it's not a matter of permissions. –

  7. python - How do I raise a FileNotFoundError properly ... - Stack …

    Mar 18, 2016 · I use a third-party library that's fine but does not handle inexistant files the way I would like. When giving it a non-existant file, instead of raising the good old FileNotFoundError: [Errno 2]...

  8. Python: FileNotFoundError not caught by try-except block

    recently i started learning Python and encountered a problem i can`t find an answer to. Idea of the program is to ask for username, load a dictionary from JSON file, and if the name is in the dictionary - print the users favourite number. The code, that loads the JSON file looks like this:

  9. Python - with open() except (FileNotFoundError ... - Stack Overflow

    If you're getting a FileNotFound error, the problem is most likely that the file name or the path to the file is incorrect. If you're trying to read AND write to a file that doesn't exist yet, change the mode from 'r' to 'w+'. It may also help to write out the full path before the file, for Unix users as: '/Users/paths/file'

  10. Python's "open ()" throws different errors for "file not found" - how ...

    This will cast a pretty wide net, and you can't assume that the exception is "file not found" without inspecting e.errno, but it may cover your use case. PEP 3151 discusses the rationale for the change in detail.

Refresh