20

While writing an application parsing command line arguments I would like to run it with various parameters.

I don't want to create a Run Configuration for every possible command line argument that I want my script to test with. Is there a way in PyCharm (and I guess with any JetBrains IDE) to make a Run Configuration that asks for the Script parameters when executed?

I am currently using PyCharm 3.1 (EAP).

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Paidhi
  • 745
  • 2
  • 8
  • 21
  • 1
    Use **"Show this page"** option ?? – LazyOne Jan 01 '14 at 13:07
  • 1
    I'm not sure it's possible...you can also ask [here](http://forum.jetbrains.com/forum/PyCharm) JetBrains staff always helps, One more option if you want to "test" with various inputs why not to use python unit test? – Kobi K Jan 01 '14 at 13:29

5 Answers5

13

I've found today that now is possible to ask for parameters using the "Prompt" macro on the "Run configuration" parameters field.

https://www.jetbrains.com/help/pycharm/code-running-assistance-tutorial.html#parameter-with-macros

11

Currently the only possibility is to use the "Before launch | Show this page" option.

yole
  • 92,896
  • 20
  • 260
  • 197
  • 2
    If 2 years later this still is the only possibility it might be useful to point out that the "Before launch | Show this page" option can be found under "Run > Edit configuration" tab.. I had a hard time finding it as a PyCharm newbie. – hellter Jan 25 '17 at 10:35
5

Although yole's answer is the de facto way to be prompted for thw arguments before running a program, it is slightly annoying because:

  • the dialog is visually overwhelming and cluttered instead of focused on what you want to do;
  • you have to tab to reach the arguments field if you want to use the keyboard exclusively (and why not?);

Nothing you could do about that. (Except maybe file a ticket. Have you done that?)


I'm just adding what I used to do before I knew about Googled for this option for the sake of completeness (obvously, this is a hack in the least glamorous sense of the term). But it did suit my workflow as I often only had discrete lines to test with, and didn't switch that often.

  1. Create a new configuration set to the same file, but with a special 'magic' parameter;
  2. Add code to your script to check if the magic is there;
  3. Use a string variable instead of sys.argv (pass it through lambda args: [__name__] + args.split() to reduce the boilerplate);
  4. ???
  5. Profit;
Community
  • 1
  • 1
Yatharth Agarwal
  • 4,385
  • 2
  • 24
  • 53
2

I'm doing this on a Mac, but hopefully this will be helpful for Windows or Linux.

Go to Run > Edit Configurations There will be a dialog box that opens. Script: file you want to run (ending with .py) Script Parameters: the command line arguments Working Directory: directory where your project is.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
pygmy
  • 49
  • 1
  • I think what @Paidhi is looking for is to be promped for the arguments after running the configuration. With your method, you have to create a new configuration for each possible argument, which is exactly what he wanted to avoid in the first place. – Lexo Aug 01 '15 at 20:06
  • This helped me. My script path was blank, giving the path to my .py file fixed the config problem. – Half Ass Dev Oct 30 '19 at 18:39
0

My simple answer is adding another wrapper as the cover in the source code which will run on the selection you made through code branch or external command or file, so choosing different branch is just a 'ddp' tap distance in vim(line change for parameter settings). You dont have to depend on pycharm updating by building your own code world:)

BrainAtom
  • 29
  • 3