Last active
September 23, 2019 00:48
-
-
Save TzuChiehHung/2c9846870206ccec6e4a7266fa50cb10 to your computer and use it in GitHub Desktop.
[Parse argument into class] #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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