dimanche 3 juillet 2016

Arguments parsed by argparse are not accessible in other files

I have parsed arguments using argparse in my main.py files. I have a few variables defined in the global_vars.py file and this file is included in main.py and other files.

I am assigning parsed arguments to global variables, but when I try to access these global variables across files other than main.py it returns None. Is there anything that I am missing, or is it a namespace problem for argparse?

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Accept arguments')
    parser.add_argument('-n', help='enter period for which you want to do the sampling')
    parser.add_argument('-b', help='enter directory for bhav copy')
    parser.add_argument('-d', help='enter directory for deliverables')
    parser.add_argument('-l', help='enter list type')

    args = parser.parse_args(namespace=None)
    var_dict = vars(args)
    bhavcopy_dir=var_dict['b']
    deli_dir=var_dict['d']
    no_of_sessions=var_dict['n']
    list_type=var_dict['l']

Aucun commentaire:

Enregistrer un commentaire