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.
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).
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
.
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.
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=""arg1" "arg2"" />
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.