I am new to python, have been working in perl. I am trying to implement getopts in python, but I am failing to understand it.
I have the below code:
I run it as:
./check.py -pdb ~/Documents/pdb/pdb_seqres.txt -list ~/Documents/pdb/list.txt
The output I get is:
when I print arg, I get blank. so it tells me there is not value passed in arg. Why?
So my pdbfile and listfile are getting blank.
Please guide.
I have the below code:
Code:
#!/usr/bin/python from Bio import SeqIO import sys, getopt def main(argv): for i in argv: print "This is in for loop "+i listfile = '' pdbfile = '' try: opts, args = getopt.getopt(argv,"pdb:list:",["pfile=","lfile="]) except getopt.GetoptError: print 'check.py -pdb <pdbfile> -list <listfile>' sys.exit(2) for opt, arg in opts: if opt in ("-pdb","--pfile"): pdbfile = arg if opt in ("-list","--lfile"): listfile = arg print 'Input file is "', listfile print 'Output file is "', pdbfile if __name__ == "__main__": main(sys.argv[1:])
./check.py -pdb ~/Documents/pdb/pdb_seqres.txt -list ~/Documents/pdb/list.txt
The output I get is:
This is in for loop -pdb
This is in for loop /home/sariya/Documents/pdb/pdb_seqres.txt
This is in for loop -list
This is in for loop /home/sariya/Documents/pdb/list.txt
Input file is "
Output file is "
This is in for loop /home/sariya/Documents/pdb/pdb_seqres.txt
This is in for loop -list
This is in for loop /home/sariya/Documents/pdb/list.txt
Input file is "
Output file is "
So my pdbfile and listfile are getting blank.
Please guide.
Comment