Python 3.11.2 on Debian bookworm
def parse_waypoint_file(filename, file=None):
file=None #gfp added for test
cherrypy.log('in parse_waypoint_file: filename = %s' % filename)
if not file:
cherrypy.log('in parse_waypoint_file: if not file block with filename = %s' % filename)
try:
file = open(filename, "r")
cherrypy.log('in parse_waypoint_file after file-open, file = %s' % file)
except:
cherrypy.log('file open() error in parse_waypoint_file with filename = %$s' % filename)
else:
cherrypy.log('file open() succeeded in parse_waypoint_file with filename = %$s' % filename)
#241207 gfp bugfix: parser fcns need 'lines' (list of lines) vs 'file'
lines = file.readlines()
….
Output:
[08/Dec/2024:01:02:48] in parse_waypoint_file: filename = Slovenia3.cup
[08/Dec/2024:01:02:48] in parse_waypoint_file: if not file block with filename = Slovenia3.cup
I’m debugging somebody else’s code, and I’m pretty new to Python (lots of C++, C#, etc). I thought I was going to solve a problem by adding the ‘ file = open(filename, “r”)
line, but instead I seem to have created a larger one. The file named in the filename parameter exists, but it may or may not be local to the web app in which this code runs.
To help me understand what was going on, I added the ‘try – except – else’ block, but the ‘except’ and ‘else’ blocks are never reached. The code acts as if the open() function hangs and never returns – but doesn’t throw an exception either.
can anyone tell me what I’m doing wrong here?
TIA,
Frank