[Python-Dev] Criticism of execfile() removal in Python3 (original) (raw)

Paul Sokolovsky pmiscml at gmail.com
Tue Jun 10 04:23:12 CEST 2014


Hello,

I was pleasantly surprised with the response to recent post about MicroPython implementation details (https://mail.python.org/pipermail/python-dev/2014-June/134718.html). I hope that discussion means that posts about alternative implementations are not unwelcome here, so I would like to bring up another (of many) issues we faced while implementing MicroPython.

execfile() builtin function was removed in 3.0. This brings few problems:

  1. It hampers interactive mode - instead of short and easy to type execfile("file.py") one needs to use exec(open("file.py").read()). I'm sure that's not going to bother a lot of people - after all, the easiest way to execute a Python file is to drop back to shell and restart python with file name, using all wonders of tab completion. But now imagine that Python interpreter runs on bare hardware, and its REPL is the only shell. That's exactly what we have with MicroPython's Cortex-M port. But it's not really MicroPython-specific, there's CPython port to baremetal either - http://www.pycorn.org/ .

  2. Ok, assuming that exec(open().read()) idiom is still a way to go, there's a problem - it requires to load entire file to memory. But there can be not enough memory. Consider 1Mb file with 900Kb comments (autogenerated, for example). execfile() could easily parse it, using small buffer. But exec() requires to slurp entire file into memory, and 1Mb is much more than heap sizes that we target.

Comments, suggestions? Just to set a productive direction, please kindly don't consider the problems above as MicroPython's. I very much liked how last discussion went: I was pointed that https://docs.python.org/3/reference/index.html is not really a CPython reference, it's a Python reference, and there were even motion to clarify in it some points which came out from MicroPython discussion. So, what about https://docs.python.org/3/library/index.html - is it CPython, or Python standard library specification? Assuming the latter, what we have is that, by removal of previously available feature, Python became less friendly for interactive usage and less scalable.

Thanks, Paul mailto:pmiscml at gmail.com



More information about the Python-Dev mailing list