[issue5524] execfile() removed from Python3

STINNER Victor report at bugs.python.org
Fri Mar 20 02:54:05 CET 2009


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

In "What’s New In Python 3.0" document, I can read "Removed 
execfile(). Instead of execfile(fn) use exec(open(fn).read())". The 
new syntax has two problems:
 - if the file is not encoding in UTF-8, we get an unicode error. Eg. 
see issue #4282
 - exec() doesn't support newline different than \n, see issue #4628

We need a short function which opens the Python file with the right 
encoding. Get Python file encoding and open it with the right encoding 
is a command pattern.

Attached patch proposes a function open_script() to open a Python 
script with the correct encoding. Using it, execfile() can be replaced 
by exec(open_script(fn).read()) which doesn't have to two binary file 
problems.

----------
files: open_script.patch
keywords: patch
messages: 83845
nosy: haypo
severity: normal
status: open
title: execfile() removed from Python3
versions: Python 3.0, Python 3.1
Added file: http://bugs.python.org/file13380/open_script.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5524>
_______________________________________


More information about the Python-bugs-list mailing list