Python: Extract variables out of namespace

前端 未结 2 1419
挽巷
挽巷 2021-01-12 07:13

I\'m using argparse in python to parse commandline arguments:

parser = ArgumentParser()
parser.add_argument(\"--a\")
parser.add_argument(\"--b\")
parser.add_         


        
2条回答
  •  囚心锁ツ
    2021-01-12 07:48

    You can add things to the local scope by calling locals(). It returns a dictionary that represents the currently available scope. You can assign values to it as well - locals()['a'] = 12 will result in a being in the local scope with a value of 12.

提交回复
热议问题