I'm beginning to learn how to use python to develop some tasks in the lab.
I have tried to use the getopt.getopt method to define the command line arguments but when I run the program gives an error, telling that output_file is not defined.
Here is my code:
def main(argv):
lista_file = ''
fasta_file = ''
output_file = ''
try:
opts, args = getopt.getopt(argv,"l:f:o:",["lista=","fasta=", "output="])
except getopt.GetoptError:
print 'test.py -l <lista> -f <fasta>'
sys.exit(2)
for opt, arg in opts:
if opt in ("-l", "--lista"):
lista_file = arg
elif opt in ("-f", "--fasta"):
fasta_file = arg
elif opt in ("-o", "--output"):
output_file = arg
print 'Lista is: "', lista_file
print 'Fasta is "', fasta_file
print 'Output is "', output_file
return lista_file
return fasta_file
return output_file
if __name__ == "__main__":
main(sys.argv[1:])
Thanks in advanced,
Uxue
The getopt module is deprecated, I'd suggest learning the new argparse module.