Home Ask Login Register

Developers Planet

Your answer is one click away!

user3808889 February 2016

Python: Command line arguments not read?

I'm trying to read command line arguments in python in the form:

python myprogram.py string string string

I have tried using sys.argv[1-3] to get each string, but when I have a string such as $unny-Day, it does not process the entire string. How can I process strings like these entirely?


kazagistar February 2016

Are you using a shell? $ is a special character in the shell that is interpreted as a shell variable. Since the variable does not exist, it is textually substituted with an empty string.

Try using single quotes around your parameter, like > python myapp.py '$unny-Day'.

Post Status

Asked in February 2016
Viewed 1,752 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life