ReneGe
asked on
Python 2.7 - Passing arguments
Hi there,
From the windows shell, I need to start my project by passing an argument to it.
Command line: task.py "These are strings" "9"
Where 9 is a number
Thanks for your help,
Rene
From the windows shell, I need to start my project by passing an argument to it.
Command line: task.py "These are strings" "9"
Where 9 is a number
print "argument1"
type (argument1)
print("") #CLRF is intended here
print argument2 + 100
type (argument2)
Thanks for your help,
Rene
ASKER
Hi Gelonida,
Thanks for your prompt response :)
Here is the output I got:
ERROR: at least 2 arguments required, but got only 0
My command line was: task.py "qq" "9"
Cheers
Thanks for your prompt response :)
Here is the output I got:
ERROR: at least 2 arguments required, but got only 0
My command line was: task.py "qq" "9"
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yea it's working
I omitted to add python in my command line :)
I'll know better next time!
Thanks for your help
Cheers
I omitted to add python in my command line :)
I'll know better next time!
Thanks for your help
Cheers
ASKER
Here is my followup question:
https://www.experts-exchange.com/questions/28971470/Python-2-7-Save-to-file.html
Cheers
https://www.experts-exchange.com/questions/28971470/Python-2-7-Save-to-file.html
Cheers
Good to know that you got it working.
However on my Windows machine I'm not obliged to type python before the command.
I guess, that your python launcher is not configured as it should be.
However on my Windows machine I'm not obliged to type python before the command.
I guess, that your python launcher is not configured as it should be.
ASKER
Maybe I should associate .py extensions to my python.exe
ASKER
Did not work! Oh well, I guess I can create a new question for this one as well
Thanks :)
Thanks :)
Open in new window
you might also look at a much more complex but very flexible solution for parsing command line arguments.
the module is called https://docs.python.org/3/library/argparse.html
it is used to parse / validate sys.argv[1:]