Running a script with command line arguments
Shafique, M. (UNU-MERIT)
kmshafique at yahoo.com
Mon May 2 13:21:31 EDT 2011
Hi,
I'm new to python and trying to run a borrowed script. The error I get suggests
that I need to give a proper command to run it. The input file is
"c26_1plus.csv" and the intended output file is "c26_1plus_backbone.csv".
Can anyone help?
BR, Shafique
Error log:
C:\Users\Shafique>extract_backbone.py c:\python26\c26_1plus.csv
c:\python26\c26_1plus_backbone
Traceback (most recent call last):
File "C:\Python26\extract_backbone.py", line 31, in <module>
alpha = float(sys.argv[3])
IndexError: list index out of range
Excerpts from code:
#!/usr/bin/env python
import sys, os
import networkx
def extract_backbone(G, weights, alpha):
blablabla...
if __name__ == '__main__':
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
usage = """python %s input_file output_file backbone_alpha [file
delimiter]"""
sys.exit(usage)
in_file = sys.argv[1]
ot_file = sys.argv[2]
alpha = float(sys.argv[3])
try:
delimiter = sys.argv[4]
except:
delimiter = "\t"
...blablabla...
# save the new edgelist:
f = open(ot_file, 'w')
for ni,nj in G_backbone.edges():
f.write("%s%s%s\n" % (ni,delimiter,nj) )
f.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110502/032a030f/attachment.html>
More information about the Python-list
mailing list