[Python-Dev] Reading Python source file
Hrvoje Niksic
hrvoje.niksic at avl.com
Wed Nov 18 07:15:16 EST 2015
On 11/18/2015 03:31 AM, Nick Coghlan wrote:
> 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.
Reading the whole script in memory will incur an overhead when executing
scripts that contain (potentially large) data embedded after the end of
script source.
The technique of reading data from sys.argv[0] is probably obsolete now
that Python supports executing zipped archives, but it is popular in
shell scripting and might still be used for self-extracting scripts that
must support older Python versions. This feature doesn't affect imports
and -c which are not expected to contain non-Python data.
Hrvoje
More information about the Python-Dev
mailing list