I have the following code:
#!/usr/bin/python
import sys
import subprocess
import random
import time
if len(sys.argv) != 7:
print "Usage: " + sys.argv[0] + " <executable> r m n p a"
sys.exit(1)
myexecutable = sys.argv[1]
r = int(sys.argv[2])
list_m = map(int, sys.argv[3].split(","))
list_n = map(int, sys.argv[4].split(","))
list_p = map(float, sys.argv[5].split(","))
list_a = map(int, sys.argv[6].split(","))
r1 = random.Random()
for m in list_m:
for n in list_n:
for p in list_p:
for a in list_a:
if a <= m:
for i in range(r):
print '%04.3f' % (r1.randint(1, 100))
seed = time.time()
r1 = random.Random(seed)
print m, n, p, a, i
command = myexecutable + " -seed "+ str(r1) + " -m "+ str(m) + " -n "+ str(n) +" -p "+ str(p) +" -a "+ str(a)
f = open("seed_" + str(r1) + "-m_" + str(m) + "-n_" + str(n) + "-p_" + str(p) + "-a_" + str(a)+ "-i_" + str(i) + ".xml", "w")
subprocess.call(command, shell=True, stdout=f)
f.close()
"Myexecutable" is a working simple program written in c++ that doesn't invoke any sophisticated library, besides boost options. Everything seems fine with it.
When I run the following code with
python generate.py
I get the peculiar, unbelievable error:
/bin/sh: 1: cannot open random.Random: No such file
If I comment the random-relevant lines and put a fixed value to r1 then I get the indendation error following (lol) :
f = open("-s_" + str(r1) + "-m_" + str(m) + "-n_" + str(n) + "-p_" + str(p) + "-a_" + str(a)+ "-i_" + str(i) + ".xml", "w") ^ IndentationError: unexpected indent
The arrow points to -a_ so it can't be an indentation error, since it is in the middle of the line right?
So I clean my project, copy to a different directory, remake and then I rerun the script. Now the loop is running normally (console output and files created) but the executable doesn't seem to run (files empty) and in every loop iteration I am still getting the error:
/bin/sh: 1: cannot open random.Random: No such file
amo If I put the comments again as mentioned above I get! :
Error: the argument ('eed') for option '--seed' is invalid
Well is this an apparent memory leak (buffer/stack overflow) by the c++ executable?
fname = "seed_" + str(r1) + "-m_" + str(m) + "-n_" + str(n) + "-p_" + str(p) + "-a_" + str(a)+ "-i_" + str(i) + ".xml"; print fname;open(fname,"w");commandstring. TheIndentationErrorwas likely a spurious problem with the editor introducing some mixed tab/space indentation while commenting out the other lines. However, on the off chance that it isn't clear why text like<random.Random object at 0x1783870>in thesubprocess.callwould cause a problem, I closed as a duplicate explaining how that would get parsed - i.e., the<and>are understood as stdin/stdout redirections.