Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72251

Re: How to run script from interpreter?

From Mark H Harris <harrismh777@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to run script from interpreter?
Date 2014-05-29 15:26 -0500
Organization Aioe.org NNTP Server
Message-ID <lm855p$1mu$1@speranza.aioe.org> (permalink)
References <mailman.979847065.10000.python-list@python.org> <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <lm53fo$jhr$1@speranza.aioe.org> <5386a7e2$0$11109$c3e8da3@news.astraweb.com>

Show all headers | View raw


On 5/28/14 10:22 PM, Steven D'Aprano wrote:
>> If you want to use python as a shell-glue you can try using system.
>>
>>   >>> from os import system
>>   >>> def <function_name>([parms])
>>   >>> .... blah blah
>>   >>> .... rc = system("<your_script_name")
>
>
> os.system is cool for quick and dirty calls to an external command. But
> for serious work, the subprocess module is better.
>

    ... yup, particularly for non trivial network related stuff.


Neither here nor there, but I just learned the ";" character command 
today for the Julia REPL, and got to thinking that python should have a 
similar way for the REPL to drop into "shell" mode for system commands.

So, I might code a clear screen in python:

def cls()
    rc = system("clear")


or in Julia

function cls()
    run(`clear`)
end

...  but on Julia we can also do this:

; clear

On the Julia REPL the ";" character drops the julia prompt into shell. I 
think the IDLE REPL should have a system shell mode. What say you?

marcus

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How to run script from interpreter? onlyvinish@gmail.com - 2014-05-28 00:44 -0700
  Re: How to run script from interpreter? Terry Reedy <tjreedy@udel.edu> - 2014-05-28 11:32 -0400
  Re: How to run script from interpreter? Mark H Harris <harrismh777@gmail.com> - 2014-05-28 11:39 -0500
    Re: How to run script from interpreter? Steven D'Aprano <steve@pearwood.info> - 2014-05-29 03:22 +0000
      Re: How to run script from interpreter? Mark H Harris <harrismh777@gmail.com> - 2014-05-29 15:26 -0500
        Re: How to run script from interpreter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-30 00:33 +0000
          Re: How to run script from interpreter? Chris Angelico <rosuav@gmail.com> - 2014-05-30 10:46 +1000
            Re: How to run script from interpreter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-30 01:49 +0000
              Re: How to run script from interpreter? Chris Angelico <rosuav@gmail.com> - 2014-05-30 12:04 +1000
                Re: How to run script from interpreter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-30 06:20 +0000
                Re: How to run script from interpreter? Chris Angelico <rosuav@gmail.com> - 2014-05-30 17:19 +1000
                Re: How to run script from interpreter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-30 11:27 +0000
                Re: How to run script from interpreter? Chris Angelico <rosuav@gmail.com> - 2014-05-30 21:46 +1000
                Re: How to run script from interpreter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-30 19:28 +0000
                Re: How to run script from interpreter? Chris Angelico <rosuav@gmail.com> - 2014-05-31 05:47 +1000
                Re: How to run script from interpreter? Terry Reedy <tjreedy@udel.edu> - 2014-05-30 11:24 -0400

csiph-web