[Python-Dev] Criticism of execfile() removal in Python3
Joseph Martinot-Lagarde
joseph.martinot-lagarde at m4x.org
Thu Jun 19 21:39:20 CEST 2014
Le 15/06/2014 05:15, Steve Dower a écrit :
> So is exec(tokenize.open(file).read()) the actual replacement for
> execfile()? Not too bad, but still not obvious (or widely promoted - I'd
> never heard of it).
>
Another way is to open the file in binary, then exec() checks itself if
an encoding is defined in the file. This is what is used in spyder:
exec(open(file, 'rb').read())
Here is the discussion for reference:
https://bitbucket.org/spyder-ide/spyderlib/pull-request/3/execution-on-current-spyder-interpreter/diff
This behavior is not indicated in the documentation but is somehow
confirmed on stackoverflow:
http://stackoverflow.com/questions/6357361/alternative-to-execfile-in-python-3-2/6357418?noredirect=1#comment30467918_6357418
---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com
More information about the Python-Dev
mailing list