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


Groups > comp.lang.python > #84616 > unrolled thread

Running a .py file iteratively at the terminal

Started byvarun7rs@gmail.com
First post2015-01-26 11:52 -0800
Last post2015-01-26 13:30 -0800
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Running a .py file iteratively at the terminal varun7rs@gmail.com - 2015-01-26 11:52 -0800
    Re: Running a .py file iteratively at the terminal Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-26 20:30 +0000
      Re: Running a .py file iteratively at the terminal varun7rs@gmail.com - 2015-01-26 13:10 -0800
        Re: Running a .py file iteratively at the terminal Cameron Simpson <cs@zip.com.au> - 2015-01-27 09:35 +1100
        Re: Running a .py file iteratively at the terminal Philip Keogh <pkeogh@compusoftcs.com> - 2015-01-26 13:30 -0800

#84616 — Running a .py file iteratively at the terminal

Fromvarun7rs@gmail.com
Date2015-01-26 11:52 -0800
SubjectRunning a .py file iteratively at the terminal
Message-ID<bea3815c-7a64-417a-959c-9408581a643e@googlegroups.com>
Hello Everyone,

I am running a python script as of now and I have to change three global values repeatedly. I'm tired of doing this manually. SO, I was wondering if there is a way to run a python command repeatedly. In my case, the command would be

srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml

Everytime I run this, I get a log file with the results. The main file is the NFV_v3....py. These are the values I intend to change iteratively and then run the command in the terminal. 
dataplane_latencybound = 200 # The delay bounds are in milli seconds
controlplane_latencybound1 = 200 # The delay bounds are in milli seconds

So, in every iteration, I would like to increase it from 0 in steps of 10 till 200. And after doing so, I'd like to run the command. But, I'm unaware of doing this using a single script. I hope some of you experts over there could help me in this issue. It can be a huge timesaver.


Thanks a lot guys
Varun RS

[toc] | [next] | [standalone]


#84619

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-01-26 20:30 +0000
Message-ID<mailman.18158.1422304262.18130.python-list@python.org>
In reply to#84616
On 26/01/2015 19:52, varun7rs@gmail.com wrote:
> Hello Everyone,
>
> I am running a python script as of now and I have to change three global values repeatedly. I'm tired of doing this manually. SO, I was wondering if there is a way to run a python command repeatedly. In my case, the command would be
>
> srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml
>
> Everytime I run this, I get a log file with the results. The main file is the NFV_v3....py. These are the values I intend to change iteratively and then run the command in the terminal.
> dataplane_latencybound = 200 # The delay bounds are in milli seconds
> controlplane_latencybound1 = 200 # The delay bounds are in milli seconds
>
> So, in every iteration, I would like to increase it from 0 in steps of 10 till 200. And after doing so, I'd like to run the command. But, I'm unaware of doing this using a single script. I hope some of you experts over there could help me in this issue. It can be a huge timesaver.
>
>
> Thanks a lot guys
> Varun RS
>

I think you need this:-

dataplane_latencybound in range(0, 205, 10):
     doSomething(dataplane_latencybound)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#84620

Fromvarun7rs@gmail.com
Date2015-01-26 13:10 -0800
Message-ID<6e21583e-8c62-413f-b54a-1e7ffaab9fd4@googlegroups.com>
In reply to#84619
Thanks a lot Mark but that would be a bit trivial. How can I run the same file multiple times? Or if I need to run two commands: 
srva@hades:~$ python NFV_nw_eu_v3_14_1_15.py --output eu_v3_14_1_15 --demand demands_v3_21_1_15.xml --xml nobel-eu.xml
srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml 

repeatedly, how can I do that? Can I write a script to perform this function?If so, can you please help me with it?
The first command generates an output file eu_v3 and the second file feeds it to the solver. This is what I intend to do multiple times. I hope I have explained it this time in a much better way. I'm sorry English is my second language and I have some problems in expressing myself at times.

Thank You

[toc] | [prev] | [next] | [standalone]


#84622

FromCameron Simpson <cs@zip.com.au>
Date2015-01-27 09:35 +1100
Message-ID<mailman.18160.1422311715.18130.python-list@python.org>
In reply to#84620
On 26Jan2015 13:10, varun7rs@gmail.com <varun7rs@gmail.com> wrote:
>Thanks a lot Mark but that would be a bit trivial. How can I run the same file multiple times? Or if I need to run two commands:
>srva@hades:~$ python NFV_nw_eu_v3_14_1_15.py --output eu_v3_14_1_15 --demand demands_v3_21_1_15.xml --xml nobel-eu.xml
>srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml
>
>repeatedly, how can I do that? Can I write a script to perform this function?If so, can you please help me with it?
>The first command generates an output file eu_v3 and the second file feeds it to the solver. This is what I intend to do multiple times. I hope I have explained it this time in a much better way. I'm sorry English is my second language and I have some problems in expressing myself at times.

Certainly you can script it. Write a tiny shell script (named "mygensolve.sh" 
for the sake of example).  Example (untested):

  #!/bin/sh
  python NFV_nw_eu_v3_14_1_15.py --output eu_v3_14_1_15 --demand demands_v3_21_1_15.xml --xml nobel-eu.xml
  python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml

Either make it executable ("chmod +rx mygensolve.sh") and run it like this:

  ./mygensolve.sh

or don't bother, and run it in an analogous fashion to your python commands:

  sh mygensolve.sh

There are multiple paths forward from here if you have many runs with filenames 
which can be enurated somehow.

Cheers,
Cameron Simpson <cs@zip.com.au>

The top three answers:  Yes I *am* going to a fire!
                        Oh! We're using *kilometers* per hour now.
                        I have to go that fast to get back to my own time.
- Peter Harper <bo165@FreeNet.Carleton.CA>

[toc] | [prev] | [next] | [standalone]


#84637

FromPhilip Keogh <pkeogh@compusoftcs.com>
Date2015-01-26 13:30 -0800
Message-ID<mailman.18167.1422346675.18130.python-list@python.org>
In reply to#84620

[Multipart message — attachments visible in raw view] — view raw

On Mon, 26 Jan 2015, varun7rs@gmail.com wrote:
> Thanks a lot Mark but that would be a bit trivial. How can I run the
> same file multiple times? Or if I need to run two commands:
> srva@hades:~$ python NFV_nw_eu_v3_14_1_15.py --output eu_v3_14_1_15
> --demand demands_v3_21_1_15.xml --xml nobel-eu.xml
>srva@hades:~$ python NFV_v3_7_10_14.py -l log --lp --xml eu_v3_14_1_15.xml 
> repeatedly, how can I do that? Can I write a script to perform this
> function?If so, can you please help me with it?  The first command
> generates an output file eu_v3 and the second file feeds it to the
> solver. This is what I intend to do multiple times. I hope I have
> explained it this time in a much better way. I'm sorry English is my
> second language and I have some problems in expressing myself at
> times.
> 
> Thank You
> 

Have you read about Bash shell brace expansion, or a one-liner loop? A
simple wrapper script could easily accomplish what you seem to be
attempting to do.

For more, see:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html
http://www.linuxjournal.com/content/bash-brace-expansion
http://wiki.bash-hackers.org/syntax/expansion/brace
http://tldp.org/LDP/abs/html/loops1.html

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web