Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
    
you can use raw_input() anywhere you want. can you use your code so that we know what do you want –  kid Feb 6 at 6:27

1 Answer 1

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
share|improve this answer
    
Thank you very much for your reply! But this is not exactly what i want. Sample code: parser.add_argument("square", type=int, help="display a square of a given number") What I want is to use these functions of argparse later when the script is already running. –  user3379410 Feb 6 at 6:25
    
@user3379410: You really should put that code and info into your question itself. In its current state your question is too vague, and may be closed unless you can narrow it down a bit. –  PM 2Ring Feb 6 at 6:48
    
Command line arguments are given when we run the script after the script name. I want the user to enter the command line arguments later also when the program asks for the user input and process it according to the command line features. Say the program asks for the input and user gives the following: -a 23 -b 33 I want to do something like parser.add_argument("-a",help="Enter first value",type="int") parser.add_argument("-b",help="Enter second value",type="int") and then use args.a and args.b in my program. I am not able to do it. Is there some I can do that? I hope I am very clear now. –  user3379410 Feb 6 at 7:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.