Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: How to run with prompt for params?

I am parsing the command line arguments in my Python code:

parser = argparse.ArgumentParser()
parser.add_argument('-e', '--epochs', type=int, default=50)
parser.add_argument('-ts', '--train-size', type=int, default=None)
parser.add_argument('-ti', '--title', default=None)
args = parser.parse_args()

So everytime I run the Python file I am able to specify title and other things I need. But since PyCharm needs run config to run, I have to manually edit run configs and save everytime I want to run.

Is there way hack to make this thing pop-up just before I run the experiment?

enter image description here

One simple way is to use the terminal from inside and just run the script with args like I do in command prompt, but I lose other configuration like the env vars, Python interpreter, conda environment, etc., when I'm doing this.

like image 851
Saravanabalagi Ramachandran Avatar asked Oct 31 '25 11:10

Saravanabalagi Ramachandran


1 Answers

This is possible now because run configuration parameters can include Jetbrains Macros, one of which triggers an input prompt. There are some limitations:

  • there is no label for the prompt
  • you can add multiple prompts, but since they aren't labelled you would have to remember the order you added the $Prompt$s in, since that will be the order they pop up when you run your Run Configuration.

example of adding prompts

example of running

like image 106
Rach Sharp Avatar answered Nov 02 '25 05:11

Rach Sharp