简体   繁体   English

将命令行参数从文件传递给pycharm

[英]Pass command line arguments to pycharm from file

I would like to pass command line arguments to pycharm script from file . 我想将命令行参数从file传递给pycharm脚本。

I am aware command line arguments can be passed via run->edit configurations -> parameters . 我知道命令行参数可以通过run->edit configurations -> parameters传递。

This method is not good enough for me because 这种方法对我来说不够好,因为

  1. In some cases the parameters line gets deleted. 在某些情况下,参数行会被删除。 not sure why, maybe git-pull? 不知道为什么,也许是git-pull? maybe other reason. 也许是其他原因。

  2. I want several configurations, and I want to save them in source control 我想要几种配置,我想将它们保存在源代码管理中

  3. I want to set those parameters programaticaly. 我想以编程方式设置这些参数。

I think taking command-line arguments from some config file would solve all my problems. 我认为从某些配置文件中获取命令行参数将解决我所有的问题。

How can I do that? 我怎样才能做到这一点?


EDIT1: 编辑1:

Use case example, as it seems my point isn't perfectly clear: 用例示例,似乎我的观点还不是很清楚:

I want to debug my code in pycharm with some configuration. 我想用一些配置在pycharm中调试我的代码。 add some breakpoints, go line by line. 添加一些断点,逐行进行。

Next I want to change configuration and debug again, with pycharm. 接下来,我想使用pycharm更改配置并再次调试。

Doing this with some script that hacks the pycharm file where the run configurations are stored seems to me like going too far. 在我看来,用一些脚本破坏运行配置存储所在的pycharm文件似乎太过分了。

Does pycharm offer no way to give it command line parameters from file? pycharm没有办法从文件中给它命令行参数吗?

PyCharm lets you have unlimited named runtime configurations, as you appear to know, so I am a little puzzled that you ask. 如您所知,PyCharm让您拥有无限的命名运行时配置,所以您问我有些困惑。 Click on the current configuraton name to the left of the green Run arrow, top right, then Edit Configurations. 单击绿色“运行”箭头左侧,右上方的当前配置名称,然后单击“编辑配置”。

These configurations live in workspace.xml . 这些配置存在于workspace.xml Nothing stopping you from checking it in. 没有什么阻止您进行检入。

For programs that take complex command line parameters it is traditional to provide a way to read the values from a named file, typically introduced by @ . 对于采用复杂命令行参数的程序,传统上提供了一种从命名文件(通常由@引入)中读取值的方法。 In argparse you specify this as follows: argparse您可以如下指定:

parser = argparse.ArgumentParser(fromfile_prefix_chars='@')

Arguments read from a file must by default be one per line. 默认情况下,从文件中读取的参数必须为每行一个。

创建以所需方式调用Python脚本的shell脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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