Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test for multiple command line arguments (sys.argv

I want to test againts multiple command line arguments in a loop

> python Read_xls_files.py group1 group2 group3

No this code tests only for the first one (group1).

hlo = []
for i in range(len(sh.col_values(8))):
   if sh.cell(i, 1).value == sys.argv[1]:
      hlo.append(sh.cell(i, 8).value)

How should I modify this that I can test against one, two or all of these arguments? So, if there is group1 in one sh.cell(i, 1), the list is appended and if there is group1, group2 etc., the hlo is appended.

like image 692
jrara Avatar asked Dec 17 '22 05:12

jrara


1 Answers

You can iterate over sys.argv[1:], e.g. via something like:

for grp in sys.argv[1:]:
  for i in range(len(sh.col_values(8))):
   if sh.cell(i, 1).value == grp:
      hlo.append(sh.cell(i, 8).value)
like image 164
Stephen Doyle Avatar answered Dec 30 '22 03:12

Stephen Doyle