Message83845
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. |
|
Date |
User |
Action |
Args |
2009-03-20 01:54:05 | vstinner | set | recipients:
+ vstinner |
2009-03-20 01:54:04 | vstinner | set | messageid: <1237514044.93.0.31573705804.issue5524@psf.upfronthosting.co.za> |
2009-03-20 01:54:03 | vstinner | link | issue5524 messages |
2009-03-20 01:54:03 | vstinner | create | |
|