I am trying to get parameters from the command line to initialize the following class
import sys
class Test(object):
def __init__(self):
for item in sys.argv:
if item.startswith("-Username"):
self.Username = item.split("Username=", 1)[1]
if item.startswith("-SessionID"):
self.sessionID = item.split("SessionID=", 1)[1]
if item.startswith("-appName"):
self.appName = item.split("appName=", 1)[1]
def run(self):
msg = '''Username {0} with SessionID {1} is using the {2} app.'''.format(self.Username, self.SessionID, self.appName)
print msg
if __name__ == '__main__':
Test().run()
In the command line I execute:
python test.py -Username=AAA, -SessionID=223, -appName=ABC
which gives the following error:
AttributeError: 'Test' object has no attribute 'Username'.
I wonder why is that? Any help is appreciated.