Call a python class from command line -


i have no python experience. trying figure out how trigger part of code command line. issue i'm finding looks "useraccount()" object , i'm not sure how trigger command line. a) useraccount? b) how call command line arguments?

        # create random use account         randomint = random.randint(1, 4294967295)         accountid = "random_id+" + str(randomint) + "@acme.com"         randomint = random.randint(1, 4294967295)         password = "random_password1_" + str(randomint)         primaryemail = accountid          useraccount = useraccount()         useraccount.accountid = accountid         useraccount.password = password         useraccount.primaryemail = primaryemail         useraccount.firstname = "random"         useraccount.lastname = "user"         useraccount.birthdaymonth = 5         useraccount.birthdayday = 31          #useraccount.firstnamephonetic = ""         #useraccount.firstnameromagi = ""         #useraccount.middlename = ""         #useraccount.middlenamephonetic = ""         #useraccount.middlenameromagi = ""         #useraccount.lastname = ""         #useraccount.lastnamephonetic = ""         #useraccount.lastnameromagi = ""         #useraccount.companyname = ""         #useraccount.securityquestion = ""         #useraccount.securityanswer = ""         #useraccount.locale = ""         #useraccount.timezone = ""         #useraccount.allowupdatenotification = false         #useraccount.allowthirdpartynotification = false          # assume we're creating user account, not requesting activate/deactivate         # permissions providing pre-created oauth client id.         oauthclientid = "";          print("  test creating account: " + useraccount.accountid + ", password: " + useraccount.password + ", email: " + useraccount.primaryemail)         accesstoken = client.createaccount(useraccount, oauthclientid)         print("    account created!")         if accesstoken:             print("      access token account: " + accesstoken)         print() 

a: useraccount class. useraccount() calling constructor of it. note construction made calling it, not new operator. b: @omgtechy stated, take @ argparse. here example might work you:

import argparse parser = argparse.argumentparser(description='useraccount creator')  parser.add_argument('--id', '-i', required=true, help='required. user account id') parser.add_argument('--password', '-p', required=true, help="required. user account's password.") parser.add_argument('--email', '-e', required=true, help='required. user account e-mail') parser.add_argument('--firstname', '-f', required=true, help="required. user account's first name") parser.add_argument('--lastname', '-l', required=true, help="required. user account's last name") parser.add_argument('--birthdaymonth', '-m', required=true, help="required. user account's birthday month") parser.add_argument('--birthdayday', '-d', required=true, help="required. user account's birthday day")  args = parser.parse_args() useraccount = useraccount() useraccount.accountid = args.id useraccount.password = args.password useraccount.primaryemail = args.email useraccount.firstname = args.firstname useraccount.lastname = args.lastname useraccount.birthdaymonth = args.birthdaymonth useraccount.birthdayday = args.birthdayday  # rest, normal  oauthclientid = "";  print("  test creating account: " + useraccount.accountid + ", password: " + useraccount.password + ", email: " + useraccount.primaryemail) accesstoken = client.createaccount(useraccount, oauthclientid) print("    account created!") if accesstoken:     print("      access token account: " + accesstoken) print() 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -