How can I give parameters to a function of a python script through the command-line? -
currently python script (taggen) has 1 function:
def sjtag(file,len_tag): import csv reader = csv.reader(open(file), dialect='excel-tab' ) row in reader: qstarts = row[1].split(",")[1:-1] n = len_tag/2 in qstarts: name = row[0] start = int(i)-n if start<0: start = 0 end = int(i)+n if end>len(row[2]): end=len(row[2]) tag = row[2][start:end] print name, i, tag, len(tag) sjtag("qstartrefseqhg19.head",80)
i want give file , len_tag parameters of sjtag function using bash comand line, this:
python ./taggen qstartrefseqhg19.head 80
how can this, or thing similar?
thanks help!
sys.argv
arguments list, first element being script name. it's list of strings, if of parameters numbers, you'll have convert them using int()
or float()
.
so, if called script so:
$ python myscript.py 1 foo bar baz
sys.argv
this:
["myscript.py", "1", "foo", "bar", "baz"]
in case, make script this:
import sys import csv def sjtag(file,len_tag): reader = csv.reader(open(file), dialect='excel-tab' ) row in reader: qstarts = row[1].split(",")[1:-1] n = len_tag/2 in qstarts: name = row[0] start = int(i)-n if start<0: start = 0 end = int(i)+n if end>len(row[2]): end=len(row[2]) tag = row[2][start:end] print name, i, tag, len(tag) if __name__ == '__main__': sjtag(sys.argv[1], int(sys.argv[2]))
Comments
Post a Comment