python argparse, how to refer args by their name -
this question argparse in python, easy
import argparse parser=argparse.argumentparser() parser.add_argument('--lib') args = parser.parse_known_args() if args.lib == 'lib': print 'aa'
this work, instead of calling args.lib, want 'lib' (i dont want type more), there way export args variable out of module (ie changing scope). can directly check value of lib not specifying name of module @ front
ps: have lot of variables, not want reassign every single one
first, i'm going recommend using args
specifier. makes clear lib
coming from. said, if find you're referring argument lot, can assign shorter name:
lib = args.lib
there's way dump attributes global namespace @ once, won't work function's local namespace, , using globals
without reason bad idea. wouldn't consider saving few instances of args.
enough reason. said, here is:
globals().update(args.__dict__)
Comments
Post a Comment