2016-08-24 4 views
1

ipythonコマンドラインをログに記録して、追加モードでファイルに出力したいと考えています。 .ipython/profile_default/startup READMEipyton起動スクリプトの構文エラー

$ 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 

下のファイルを読んで、私は

logstart -o -r -t logs/ipython.log 'append' 

logstartは魔法のコマンドで、以下の内容でファイルfirst.pyを追加してみました。私はipythonを起動しようとしているときにエラーが発生しています

File "/home/mtk/.ipython/profile_default/startup/00-first.py", line 1 
    logstart -o -r -t logs/ipython.log 'append' 
         ^
SyntaxError: invalid syntax 

この問題を解決するにはどうすればよいですか?

+1

を使用して呼び出すことができます。 '.py'ファイルは普通のPythonコードでなければならず、IPythonの特別な構文はありません。 –

答えて

1

「トーマス・K」のコメントにも解決策のように見えますが、ここで私は彼が正しい述べたように、我々は唯一のスタートアップフォルダに*の.pyファイルでPythonのコードを持つことができます自分自身

を見つけた別の解決策があり、I私の以前のテキストを以下に置き換えました。マジックのコマンドは `.ipy`拡張子を使用して、スタートアップファイルに魔法のコマンドを使用するにはrun_line_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", "") 
関連する問題