2
I need to receive three lists generated in the shell to process in Python:
l1=4 3 2 1
l2=2 1 3 4
l3=1 2 3 4
In the shell script step this way:
python3 orth_median.py ${o_l1[*]} ${o_l2[*]} ${o_l3[*]}
Python takes 12 numbers.
In python I had to convert the 12 numbers into 3 lists to have the 3 lists again. Is this the best way or is there another way to do it? I am beginner working with shell script.
if __name__ == "__main__":
if len(sys.argv)>11:
size1=len(sys.argv[1:])/3
l1=[sys.argv[1:][0],sys.argv[1:][1],sys.argv[1:][2],sys.argv[1:][3]]
l2=[sys.argv[1:][4],sys.argv[1:][5],sys.argv[1:][6],sys.argv[1:][7]]
l3=[sys.argv[1:][8],sys.argv[1:][9],sys.argv[1:][10],sys.argv[1:][11]]
A=np.array(generate_matrix(l1, int(size1)))
B=np.array(generate_matrix(l2, int(size1)))
C=np.array(generate_matrix(l3, int(size1)))
M = orth_median1(A, B, C)
print('o_m', M)
else:
print('No arguments provided.')
Your answer shows me that I need to learn more. Thank you! In the last line of code you posted you feiz two tasks in a row sounds. how could put in two lines of code?
– shermila
@shermila Would that be: https://repl.it/repls/TiredColossalQuarks#main.py ? Something else: If the answer solved your problem, you can accept it, see here how and why to do it. It is not mandatory, but it is a good practice of the site, to indicate to future visitors that it solved the problem. Don’t forget that you can also vote in response, if it has found it useful.
– hkotsubo