2012-04-27 41 views
6

セッション間でpdb(pythonデバッガ)のコマンド履歴を保存する方法はありますか?また、履歴の長さを指定することはできますか?pdbにコマンド履歴を保存

これは、質問How can I make gdb save the command history?と似ていますが、gdbの代わりにpdbの場合に似ています。私はあなたがIPythonでこれを行うことができると思い

-manyおかげ

+0

? – Keith

+0

Ubuntu 11.04 Python 2.7.1+(r271:86832、2011年4月11日、18:13:53) [GCC 4.5.2] on linux2 – vkontori

+0

この問題は解決しましたか?同様の機能も持っていたいと思います。 – Phani

答えて

-1
+1

これはipdbで確実にできるのですか?以前のipdbセッションから自分の履歴を取得することができませんでした。 – Phani

+1

これは誤りです、ipdbは履歴をサポートしていません。 –

+0

IPDBはIPythonと同じ魔法のコマンドをサポートしていません。 IPDBに '%magic-commands'を入力する方法がわからない限り、downvoteはそのままです。 –

1

私はそこにあると信じていません"株式" pdbの方法。しかし、私はそれを行う代替デバッガを書いた。

ソースからのPycopiaをインストールする:http://code.google.com/p/pycopia/source/checkoutとpycopia.debuggerにあります。

5

NB:私たちは歴史を保存するためのreadlineを指示することができるようhttps://wiki.python.org/moin/PdbRcIdea

PDBがreadlineのを使用しています:

.pdbrc

# NB: This file only works with single-line statements 
import os 
execfile(os.path.expanduser("~/.pdbrc.py")) 

これだけのpythonで2

クレジットをテストしています.pdbrc.py

def _pdbrc_init(): 
    # Save history across sessions 
    import readline 
    histfile = ".pdb-pyhist" 
    try: 
     readline.read_history_file(histfile) 
    except IOError: 
     pass 
    import atexit 
    atexit.register(readline.write_history_file, histfile) 
    readline.set_history_length(500) 

_pdbrc_init() 
del _pdbrc_init 
2

投稿thisを参照してください。 pdbに履歴を保存することは可能です。デフォルトでは、pdbは複数の行を読みません。したがって、すべての関数は1行にする必要があります。 〜/ .pdbrcで

:あなたはプラットフォームを使うのです

import atexit 
import os 
import readline 

historyPath = os.path.expanduser("~/.pyhistory") 

def save_history(historyPath=historyPath): import readline; readline.write_history_file(historyPath) 

if os.path.exists(historyPath): readline.read_history_file(historyPath) 

atexit.register(save_history, historyPath=historyPath) 
関連する問題