Passing Arguments to file via VS

Nov 5, 2012 at 4:13 AM

I am a new Python developer learning programming at my university.  For some of our recent assignments, we had to run a file via the command prompt and pass arguments to it.

For example, ran the line

python hw5.py tweets.txt

In the code I had to write, used sys.argv to refer to the file (tweets.txt) which contained the input for the program.  The program was a mock twitter client, which followed simple commands, like add user, add tweet, or print friends.  The file (tweets.txt) contained lines (which were read in one at time), telling the program what to do.

Is there any way to do this in Visual studio?  Or will I always have to run in in the windows command prompt?

Thanks for helping a newbie programmer.

Nov 5, 2012 at 4:55 AM

You can specify the arguments to be used when launching your script from PTVS in project properties. To get there, right-click on the project node in Solution Explorer, select "Properties", and then in the window that opens, select the "Debug" tab on the left. "Script arguments" textbox there is the one that you want.

Nov 5, 2012 at 5:00 AM

There is nothing in the solution explorer.  Is just lists "Solution 'Solution1' (0 Projects)"

Am I doing something wrong?  I have never used this solution explorer before.

Nov 5, 2012 at 6:39 AM

Generally speaking, when you want to launch your Python script(s) from VS (and not just edit it there), you'll need to create a project. File -> New -> Project will do the trick, then look for Python in the tree of project types on the left in the New Project dialog that'll open. In Python Tools 1.5, there is an option "From Existing Python Code", which should make it very simple for you if you already have a bunch of Python files in a folder, and would just like to treat them as a single program.