Ipython ipyton启动脚本语法错误

Ipython ipyton启动脚本语法错误,ipython,startup,Ipython,Startup,我希望总是记录ipython命令行,并以追加模式输出到文件。在读取.ipython/profile\u default/startupREADME下的文件时 $ cat README This is the IPython startup directory .py and .ipy files in this directory will be run *prior* to any code or files specified via the exec_lines or exec_fil

我希望总是记录ipython命令行,并以追加模式输出到文件。在读取
.ipython/profile\u default/startup
README下的文件时

$ cat README 
This is the IPython startup directory

.py and .ipy files in this directory will be run *prior* to any code or files specified
via the exec_lines or exec_files configurables whenever you load this profile.

Files will be run in lexicographical order, so you can control the execution order of files
with a prefix, e.g.::

    00-first.py
    50-middle.py
    99-last.ipy
我尝试先添加一个包含以下内容的文件first.py

  logstart -o -r -t logs/ipython.log 'append'
logstart
是一个神奇的命令。当我尝试启动ipython时,我的错误率已降至最低

  File "/home/mtk/.ipython/profile_default/startup/00-first.py", line 1
    logstart -o -r -t logs/ipython.log 'append'
                         ^
SyntaxError: invalid syntax
如何解决这个问题?

“Thomas K”的评论看起来也是一个解决方案,但这里是我自己找到的不同解决方案

正如他所说的,我们只能在startup文件夹中的*.py文件中使用python代码,我用下面的内容替换了前面的文本。可以使用
run\u line\u Magic
方法调用Magic命令

get_ipython().run_line_magic(u"logstart", u"-o -r /home/mt/Dropbox/a/logs/ipython_log.py append")
get_ipython().run_line_magic(u"logstate", "")

要在启动文件中使用magic命令,请使用
.ipy
扩展名
.py
文件必须是常规Python代码,没有IPython特殊语法。