文件内容作为PyCharm运行配置参数

问题描述 投票:0回答:1

我正在尝试启动可能带有txt文件(config.txt)中列出的一些参数的主Python脚本。

因为参数几乎每次启动都会更改,所以我不想每次都键入它们。它们实际上不是一个“配置”,但我没有找到正确的文件名(这是另一个故事)。

见下文:

-param1   1
-param2   2
-verbose

使用PyCharm的运行配置Run/Debug PyCHarm Configuration

我最终想做的是:python C:\somewhere\main.py -param1 1 -param2 2 -verbose

代替当前行为:python C:\somewhere\main.py config.txt

顺便说一下,程序错过了(显然)。

#32951846


我已经尝试过Windows for“启动前:激活工具”

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

但是它仅将config.txt的最后一行保留在ARGS内。

#51948712


我还试图将文件内容通过管道传递到我的python主程序中,例如:

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

但它也不起作用。

#syntax-redirection

python windows pycharm run-configuration
1个回答
0
投票

我是对的,您想看到类似https://youtrack.jetbrains.com/issue/PY-5543的内容吗?

考虑使用以下插件:https://plugins.jetbrains.com/plugin/7861-envfile/

© www.soinside.com 2019 - 2024. All rights reserved.