Skip to content

Instantly share code, notes, and snippets.

@TzuChiehHung
Last active September 23, 2019 00:48
Show Gist options
  • Save TzuChiehHung/2c9846870206ccec6e4a7266fa50cb10 to your computer and use it in GitHub Desktop.
Save TzuChiehHung/2c9846870206ccec6e4a7266fa50cb10 to your computer and use it in GitHub Desktop.
[Parse argument into class] #python
import argparse
class MyClass(object):
def __init__(self, foo, bar):
self.foo = foo
self.bar = bar
def Print(self):
print self.foo
print self.bar
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('foo')
parser.add_argument('bar')
args = parser.parse_args()
args_dict = vars(args)
c2 = MyClass(**args_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment