0
我不知道爲什麼下面的代碼不工作 - 我得到的錯誤getopt不太能工作,我做錯了什麼?
NameError: name 'group1' is not defined.
的代碼能正常工作之前,我試圖用getopt的..我試圖解析命令行輸入,以便例如,如果我把
python -q file1 file2 -r file3 file4
file1和file2成爲我的第一個循環輸入爲'group1'。
import sys
import csv
import vcf
import getopt
#set up the args
try:
opts, args = getopt.getopt(sys.argv[1:], 'q:r:h', ['query', 'reference', 'help'])
except getopt.GetoptError as err:
print str(err)
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
print "Usage python -q [query files] -r [reference files]"
print "-h this help message"
elif opt in ('-q', '--query'):
group1 = arg
elif opt in ('-r', '--reference'):
group2 = arg
else:
print"check your args"
#extract core snps from query file, saving these to the set universal_snps
snps = []
outfile = sys.argv[1]
for variants in group1:
vcf_reader = vcf.Reader(open(variants))