[Python-Dev] Reading Python source file (original) (raw)

Guido van Rossum guido at python.org
Tue Nov 17 21:46:49 EST 2015


Aha, so the only code path that's being replaced is the code that reads the script file when invoking "python FILE" or "python <FILE" or "cat FILE | python" (but not "python" reading from a tty device)? That makes the whole endeavor even more attractive!

On Tue, Nov 17, 2015 at 6:31 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

On 18 November 2015 at 02:50, Guido van Rossum <guido at python.org> wrote:

On Tue, Nov 17, 2015 at 8:20 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:

On 17.11.15 11:59, M.-A. Lemburg wrote:

I don't think these situations are all that common, though, so reading in the full source code before compiling it sounds like a reasonable approach. We use the same simplification in eGenix PyRun's emulation of the Python command line interface and it has so far not caused any problems. Current implementation of import system went the same way. As a result importing the script as a module and running it with command line can have different behaviours in corner cases. I'm confused. Of course these two behaviors differ, since Python uses a different name. Not sure how this relates to the REPL. I think Serhiy was referring to the fact that importlib already reads the entire file before compiling it - since the import abstraction doesn't require modules to be files on disk, it uses the getcode() API on the module loader internally, which is typically implemented by calling getsource() and then passing the result to compile(). That behaviour is then inherited at the command line by both the -m switch and the support for executing directories and zip archives. When we consider that the "-c" switch also executes an in-memory string, direct script execution is currently the odd one out in not reading the entire source file into memory first, so Serhiy's proposed simplification of the implementation makes sense to me. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list