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

M.-A. Lemburg mal at egenix.com
Thu Nov 19 04:47:24 EST 2015


On 17.11.2015 16:22, Guido van Rossum wrote:

On Tue, Nov 17, 2015 at 1:59 AM, M.-A. Lemburg <mal at egenix.com> wrote:

[moving from read source line by line to reading all in one go] 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. Curious how you do it? I'd actually be quite disappointed if the amount of parsing done by the standard REPL went down.

Oh, that's easy:

    elif sys.argv[0] == '-' and not (pyrun_as_string or pyrun_as_module):
        # Read the script from stdin
        pyrun_as_string = True
        pyrun_script = sys.stdin.read()

and then, later on:

    # Run the script
    try:
        pyrun_execute_script(pyrun_script, mode)
    except Exception as reason:
        if pyrun_interactive:
            import traceback
            traceback.print_exc()
            pyrun_prompt(banner='')
        else:
            raise
    else:
        # Enter interactive mode, in case wanted
        if pyrun_interactive:
            pyrun_prompt()

The REPL is not affected by this, since we use the standard code.interact() for the prompt. This reads the entry line by line, joins the lines and tries to compile the entry every time it receives a new line until it succeeds or fails.

Serhiy's proposed change should not affect this mode of operation.

-- Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Experts (#1, Nov 19 2015)

Python Projects, Coaching and Consulting ... http://www.egenix.com/ Python Database Interfaces ... http://products.egenix.com/ Plone/Zope Database Interfaces ... http://zope.egenix.com/


2015-10-23: Released mxODBC Connect 2.1.5 ... http://egenix.com/go85

::: We implement business ideas - efficiently in both time and costs :::

eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/



More information about the Python-Dev mailing list