简体   繁体   中英

Pass command line arguments to pycharm from file

I would like to pass command line arguments to pycharm script from file .

I am aware command line arguments can be passed via 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? 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:

Use case example, as it seems my point isn't perfectly clear:

I want to debug my code in pycharm with some configuration. add some breakpoints, go line by line.

Next I want to change configuration and debug again, with pycharm.

Doing this with some script that hacks the pycharm file where the run configurations are stored seems to me like going too far.

Does pycharm offer no way to give it command line parameters from file?

PyCharm lets you have unlimited named runtime configurations, as you appear to know, so I am a little puzzled that you ask. 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 . 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:

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

Arguments read from a file must by default be one per line.

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

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