[ python-Bugs-1674503 ] execfile() response to syntax errors

SourceForge.net noreply at sourceforge.net
Tue Mar 6 00:38:25 CET 2007


Bugs item #1674503, was opened at 2007-03-05 16:38
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1674503&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jonathan Griffitts (jcgriffitts)
Assigned to: Nobody/Anonymous (nobody)
Summary: execfile() response to syntax errors

Initial Comment:
Python 2.5 seems to have an anomaly when execfile() encounters syntax errors.  

If I use execfile() to execute a file that contains a syntax error, it throws the expected SyntaxError exception but does not close the source file.  Since the file is still open, an external program can't modify it to fix the syntax error.

I have noticed this problem in Python 2.5 on Windows 2000 and Windows XP.  I tried to reproduce it on Python 2.3 on BSD Unix but it didn't seem to happen there.


---------------- spam.py ---------------------

[intentional-syntax-error)
----------------------------------------------

The following is my console session:

----------------------------------------------
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile('spam.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "spam.py", line 1
    [intentional-syntax-error)
                             ^
SyntaxError: invalid syntax
>>>
----------------------------------------------

At this point file spam.py remains open until Python exits.  There's no obvious way to close the file from within the script because there is no file object.  Under Windows, this prevents spam.py from being edited, 
renamed, or deleted.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1674503&group_id=5470


More information about the Python-bugs-list mailing list