简体   繁体   中英

Processing input as command line arguments in Python

I have understood the concept of command line arguments in Python and I am able to use it too. During my program run I want user to input the details in same way as we can do in command line arguments. Basically I want to use command line features again during my program run. Can I do that? If yes, how? I hope I have put my question clear enough to understand. Any help would be appreciated. Thank you!

You can try this, it could simulate the interactive cmd line

print ">>"

while True:
    inputStr = raw_input(">>what is your choice, input exit to quit\n>>")
    if inputStr == "exit":
        print "bye"
        break
    else:
        msg = ">> This is your input :%s" % inputStr
        print msg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM