'File content as PyCharm run configuration parameters

I'm trying to launch may main Python script with some arguments listed in a txt file (config.txt).

Because parameters change almost every launch and I dont want to type them every time. They are not literally a "config" but I didn't find the correct file name (that's an other story).

See below:

-param1   1
-param2   2
-verbose

Using Run Configuration of PyCharm. Run/Debug PyCHarm Configuration

I would like to finally do something like : python C:\somewhere\main.py -param1 1 -param2 2 -verbose

Instead of current behavior :python C:\somewhere\main.py config.txt

Which, by the way, is missed understood by the program (obviously).

#32951846


I already tried windows for loops in the section "before launch: activate tools":

$: for /f "delims=" %x in (config.txt) do set ARGS=%ARGS%%x
$: python  C:\somewhere\main.py %ARGS%

But it only keep the last line of the config.txt inside ARGS.

#51948712


I also tried to pipe the content of the file into my python main program like:

python C:\somewhere\main.py < config.txt

But it do not work neither.

#syntax-redirection



Solution 1:[1]

Am I right that you'd like to see something like https://youtrack.jetbrains.com/issue/PY-5543?

Consider using the following plugin: https://plugins.jetbrains.com/plugin/7861-envfile/

Solution 2:[2]

This is not exactly what you were asking for, but you can follow this guideline to store the run configurations in a file and then modify the file, share it or add to git.

The key steps are to tick the box "Store as project file" in PyCharm's "Run/Debug Configurations" window. This will create the new subfolder "runConfigurations" in the ".idea" folder in the project folder.

The folder will contain an xml file with the line

<option name="PARAMETERS" value="&quot;arg1&quot; &quot;arg2&quot;" />

where "arg1" and "arg2" are the arguments which are passed to your script.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2235698
Solution 2 openwater