[Baypiggies] importing variables into python namespace using argparse module

Abhishek Pratap abhishek.vit at gmail.com
Wed Sep 7 22:11:00 CEST 2011

Hey All

This might sound naive as I am trying to learn python.

I am using argparse to parse the command line arguments but I am not
sure how they variables created by it are imported into python's
current namespace for downstream usage.


parser = argparse.ArgumentParser(description='Process some integers')

parser.add_argument('--file_1', nargs=1 , type=file, required=True,
help='Name of file 1')
parser.add_argument('--file_2', nargs=1 , type=file, required=True,
help='Name of file 2')

print "file 1 is %s) % file_1 ## as expected gives me error
NameError: name file_1' is not defined

What I am not sure is now how can I use the file_1 and file_2 variable
for anything downstream.

PS: Please let me know if this is not a appropriate forum to push such
questions and if there are other mailing list that I could use coz in
the coming days I am sure to send in a lot of email traffic.


More information about the Baypiggies mailing list