Python Forum
where is FileNotFoundError at?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where is FileNotFoundError at?
#1
i got a traceback and error in 3.5.2 that said FileNotFoundError was not defined on an except FileNotFoundError: statement.  the documentation appears to say that it is builtin.  but apparently not.

i say "appears" because there are so many exceptions listed and so much upscrolling to do that i could have missed something.

edit: adding traceback

Output:
Traceback (most recent call last):   File "setup_usr_local_bin.py", line 84, in <module>     setup('addr')   File "setup_usr_local_bin.py", line 34, in setup     if exists(nn):   File "setup_usr_local_bin.py", line 21, in exists     except FileNotFoundError: NameError: global name 'FileNotFoundError' is not defined
i had to scroll way back on my terminal screen to find this.  this was running under user "root" at the time.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Interestingly FileNotFoundError is defined in my py3 install (3.5.1) but the docs seem to indicate using OSError and I can't find documentation for FileNotFoundError.
https://docs.python.org/3/library/except...ml#OSError

In my own personal experience I always caught IOError for this (which seems to be folded into OSError now).

Edit:
Actually here is the doc for FileNotFoundError
https://docs.python.org/3/library/except...FoundError
Sure seems it should still be defined in current distros.

https://www.python.org/dev/peps/pep-3151/
Reply
#3
i would like to have a program (not written in cobol or perl or java) that can be given a name and it would output what module(s) has/have it, one line per finding.  it might need to be pre-run with "--build" to build an index somewhere.

and now this:
Output:
lt1/root /root 102# py3               Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> FileNotFoundError <class 'FileNotFoundError'> >>>
hmmm (60 Hz)

i found a logic error in my bash shell command handler that was incorrectly running it under python2 instead of python3.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
during development, I'll include:
except:
    print("Unexpected error:", sys.exc_info()[0])
only until I have identified what might be thrown, and replace with the specific exception
after one is thrown

the FileNotFoundError is documented (what there is of it) here: https://docs.python.org/3.5/library/exceptions.html
Reply
#5
right, and i had been ass-u-ming this command was running on python3 all along.  it has #!/usr/bin/env python3  i guess it just worked in python2 until i modified it.  funny thing is during debugging i added import os because another script that worked with FileNotFoundError also had import os.  then i ran it like py3 setup_usr_local_bin.py and it worked!  can you imagine how silly that seemed?  it was when i added some debug echos to the bash code handling it due to another problem that i discovered an error in the bash code that looked at the #! line to see which python version to run.  that code (i wrote) had the error.  it was many lines of bash code to handle commands in special ways like letting me leave .py on the script file name but type the command name in without the .py.  in the future i plan to just have that bash code hand the whole job over to some python code.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,587 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,660 Sep-12-2022, 04:50 AM
Last Post: python202209
  FileNotFoundError: [Errno 2] No such file or directory: 5l3y3r 6 8,136 Nov-02-2020, 12:48 PM
Last Post: 5l3y3r
  Shutil FileNotFoundError: Errno 2 Help lord_kaiser 8 10,544 Aug-10-2020, 08:45 AM
Last Post: lord_kaiser
  Getting FileNotFoundError: [Errno 2] ,if tries to acees same file from sub-directory pmpinaki 2 2,518 May-04-2020, 03:39 PM
Last Post: pmpinaki
  FileNotFoundError: [Errno 2] No such file or directory saqib1066 23 24,481 Mar-16-2020, 01:25 PM
Last Post: saqib1066
  FileNotFoundError managment sal 2 2,580 Oct-23-2019, 09:18 AM
Last Post: sal
  [split] FileNotFoundError...System cannot find the path specified powerrocker 1 2,062 Oct-03-2019, 09:09 AM
Last Post: buran
Question pdfkit.from_string('Hello!','out.pdf') gives FileNotFoundError sipriusPT 3 9,344 Sep-19-2019, 01:44 PM
Last Post: snippsat
  FileNotFoundError: No such file or no access agatte 2 4,953 Sep-12-2019, 08:48 AM
Last Post: agatte

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020