0

First off I looked in the documentation and found this: http://www.tutorialspoint.com/python/python_command_line_arguments.htm

And then I also found this: how to execute a python script file with an argument from inside another python script file

I am using pycharm 2.7.3 and when I try to run my script I get and error (the error is not pycharm related). THe only way around this error I have found out to be is to run the script through the windows PowerShell with a couple of "arguments" (is that what its called?)

The code that follows is what makes up my script, temp.py

from sys import argv
# this what the Ide fails to run

scripts, first, second, third = argv
print "The script is called:", scripts
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

Next is what I types into the powershell NOTE: The above code is temp.py

python temp.py first 2nd 3rd

1) What are those pieces of text called that appear after the "python temp.py", is it arguments?

2) Is it possible to run the code with the so called arguments in the IDE (I am using pyCharm)

3) If '2)' = True, how so?

1 Answer 1

1

1) What are those pieces of text called that appear after the "python temp.py", is it arguments?

Yes, the things you pass after temp.py on the shell are called "arguments", or "command line arguments". Sometimes they're called "parameters" instead, sometimes with the word "actual" as a prefix.*

And note that temp.py and all of its arguments are themselves arguments of python.

The sys.argv variable that you're using specifically gives you:

The list of command line arguments passed to a Python script…


2) Is it possible to run the code with the so called arguments in the IDE (I am using pyCharm)

Yes. Almost every IDE has a way to do this.


3) If '2)' = True, how so?

Read the PyCharm docs for details, but IIRC, they're part of the "run/debug configuration"; when you use the "Edit Configurations" command and edit one, there's a box labeled "Script Parameters" for you to enter the arguments.


* Using "parameters" is a bit misleading. Speaking technically, using the terminology Python uses for function calling, you should say that your script has a single parameter, a variable-positional parameter which gathers all of the arguments used to call it, which you can access as sys.argv. But as you can guess, nobody actually says things that way. If someone says "command line parameters" or "script parameters", they mean "the things in sys.argv".

Sign up to request clarification or add additional context in comments.

2 Comments

Okay thank you for your reply it now works once I Run > Edit Configurations > Script Parameters.
@user320: Thanks for giving the exact name of the field to edit. I've updated the answer to make it more useful for future readers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.