0

I have a basic question. I would like to make running Arc.py several times with different input (R0.arg)and output (V0.art) The idea is to repeat the command like this:

Arc.py R0.arg V0.art

Arc.py R1.arg V1.art

Arc.py R2.arg V2.art

Arc.py R3.arg V3.art

Arc.py R4.arg V4.art

Arc.py R#.arg V#.art

...

..

.

until #=1000.

Could you help me, please?

arton
  • 3
  • 1
  • 2

1 Answers1

2

Is there anything stopping you from doing the following?:

import whatever

def main(arg1):
    # routine to be run

if __name__=='__main__':
    sys.exit(main(sys.argv[1]))

In the other python file, just import the module and call the routine in a loop:

import otherfile

for i in xrange(1000):
    otherfile.main(arg1)
adchilds
  • 963
  • 2
  • 9
  • 22
  • Thank you for the reply, however I tried the first method, but it doesnt work. Could you detail a bit more, please? – arton Jun 28 '12 at 14:55
  • You create two python files. One contains the routine that you want to run. The other file calls that routine in a loop with given arguments. I'm not too sure how else to explain that :-/ What do you mean you tried the first method? You should implement both blocks of code above (tailored to your needs, of course), not just the first. Sorry if I'm misunderstanding. – adchilds Jun 28 '12 at 14:59
  • Because I am just not expert in Python. that s why I asked to tailored to my example ;) Thank you anyway – arton Jun 28 '12 at 15:11
  • All you have to do is place your code in the main() method and fix the imports and add a way to change the arguments. I'm no Python expert by any means either, just takes a little patience. – adchilds Jun 28 '12 at 15:15
  • 1
    You should use `xrange` instead of `range`, assuming Python 2. – Wooble Jun 28 '12 at 17:17