I am new to python and work with Microsoft Visual Studio
I have to run this(but it says need more than 1 value):
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
I understood that I have to type that(for example) in order to run the code:
python ex13.py first 2nd 3rd
but where do I need to write it?
In the Visual Studio there is only Start Button for running the script
Thanks
indicate your specific arguments. After all, you can execute your created task with Ctrl + Shift + B and choose the new "Run Python with argument" task.
Visual Studio provides open-source support for the Python language through the Python Development and Data Science workloads (Visual Studio 2017 and later) and the free Python Tools for Visual Studio extension (Visual Studio 2015 and earlier). Visual Studio doesn't support Python on Mac now.
You can use the Python Tools for Visual Studio plugin to configure the python interpreter. Create a new python project and then go to Project Properties | Debug and enter your arguments. You don't need to type python
or your script name, only the parameters. Specify the script in General | Startup File. Click Start Debugging to run your script with the parameters specified.
I wrote a example. For every Argument, you test for correct parameter in the for loop. You can put the parameters in the propertys dialog of your project. Under debug, it is the Script Arguments "-i aplha.txt" for example.
import sys
import getopt
def main(argv):
try:
opts, args = getopt.getopt(argv,"hi:",["ifile="])
except getopt.GetoptError:
print 'test.py -i <inputfile>'
sys.exit(2)
for opt, arg in opts:
if opt in ("-i", "--ifile"):
inputfile = arg
print 'Input file is "', inputfile
if __name__ == "__main__":
main(sys.argv[1:])
You can enter your command line options by doing the following:
Right click on your project in the solution explorer and choose Properties.
Click on the Debug Tab
In script arguments enter your command line options
Run the project
For example my code has:
opts, args = getopt.getopt(argv,"p:n:",["points=","startNumber="])
in the script arguments I enter -p 100, -n 1
I am using Visual Studio 2017.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With