使用 IPython 在 运行 脚本中解析参数

Parsing arguments while running script with IPython

我经常 运行 使用 ipython -iipython --pdb 编写脚本。我想制作一个脚本来解析参数而不干扰 运行 以这种方式。我试图在下面的文件 ipy_parse.py:

中执行此操作
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
    '-lf', '--proglogfile',
    help="File for logging",
    dest="plogfile",
    type=str
)

args = parser.parse_args()
print(args.plogfile)

但是,当我 运行 使用 ipython ipy_parse.py --proglogfile="wat" 时,我得到以下输出:

[TerminalIPythonApp] WARNING | Unrecognized alias: '--proglogfile=wat', it will probably have no effect.
None

尽管这个脚本在 运行 和 python ipy_parse.py --proglogfile="wat" 时正常工作。如何在不干扰 IPython 个参数的情况下解析参数?

您可以使用 --:

将 ipython 参数与脚本参数分开
ipython ipy_parse.py -- --proglogfile="wat"