简体   繁体   中英

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. 运行/调试 PyCHarm 配置

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

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM