With Python argv and input () command-line tool production

## .py file command line parameters and pass
code example below, unpacks the parameters of the
`` `
from the argv SYS Import
Import Requests
Import JSON
Import Time

Script, the userId, the userName, enterpriseId the argv =
Parameter = { "the userId": the userId {}, "the userName": {} the userName, "enterpriseId": {} enterpriseId, "In Flag": "sended"}
RQ = requests.put ( "http://test.xxxxxx.com/mail/receiveSendedAndRubbishMail", Data = Parameter)
Data = rq.json ()
Print (json.dumps (Data, indent =. 4, sort_keys = True, ensure_ascii = False))
`` `
when the actual command line input command: `
``
Python filename.py the userId the userName enterpriseId
`` `
## using the input parameter function acquired by one
` ``
Import Requests
Import JSON
Import time
prompt = '>>>'

print("Please Input 'userID', For Example>>>1400")
userId = input(prompt)
print("Please Input 'userName', For Example>>>yangdawei_10171")
userName = input(prompt)
print("Please Input 'enterpriseId', For Example>>>10171")
enterpriseId = input(prompt)
print(f"The Program is starting to syc {userId}--{enterpriseId}--{userName}'s email and how much time is going to spend that's depends on how many emails in outbox, Just wait...")
before_syc_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print("current time is" + ' ' + before_syc_time)
parameter = {"userId":{userId},"userName":{userName},"enterpriseId":{enterpriseId},"flag":"sended"}
rq = requests.put("http://admin.xxxxxxx.com/mail/receiveSendedAndRubbishMail", data=parameter)
data = rq.json()
print(json.dumps(data, indent=4, sort_keys=True, ensure_ascii=False) )
after_syc_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print("current time is" + ' ' + after_syc_time)

the INPUT ( 'Press the Enter to Exit Program and the then the this use Close Dialog ....')
`` `
when the actual execution of the command line enter the command: `
``
Python filename.py
`` `
== You can use the packaging tools, such as the previous blog post mentioned pyinstaller packed into .exe, not everyone in the command line content ==

Guess you like

Origin www.cnblogs.com/davieyang/p/11681959.html