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

    Possible duplicate of Python's "open ()" throws different errors for "file not found" - how to handle both exceptions?

  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 f.readlines() except: print 'oops' and can't write with open("a.txt") as f: print f.readlines() else: print 'oops' Enclosing with in a ...

  6. How do I raise a FileNotFoundError properly? - Stack Overflow

    Mar 18, 2016 · I don't want to handle the missing file, don't want to catch nor handle the exception, don't want to raise a custom exception, neither want I to open the file, nor to create it if it does not exist.

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

  8. Python - with open() except (FileNotFoundError)? - Stack Overflow

    It seems strange to me that with open (file, 'r') can report FileNotFoundError: [Errno 2] but I can't catch that in some way and continue on. Am I missing something here or is it really expected...

  9. How Can I Use Python FileNotFoundError to print name of missing …

    Nov 17, 2016 · As there are two different filenames specified, it could be either of those files that are not present. Does Python provide this kind of functionality in its built-in exceptions?

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

    I have a script where a user is prompted to type a filename (of a file that is to be opened), and if the file doesn't exist in the current directory, the user is prompted again. Here is the short v...

Refresh