2010-05-04 10 views
6

Sto eseguendo il debug del codice Python con pdb. Il codice bisogno di input da stdin, come:Come pdb codice Python con input?

python -m pdb foo.py < bar.in 

Poi i PPB accetteranno la bar.in come comandi. Come dire a pdb che l'input è per foo.py e non per pdb?

risposta

1

Un tipo di lavoro lordo intorno è quello di mettere cont all'inizio del bar.in:

cont 
one 
two 
three 
four 


[email protected] ~$ python -m pdb cat.py < bar.in 
> ~/cat.py(1)<module>() 
-> import sys 
(Pdb) one 
two 
three 
four 
The program finished and will be restarted 
> ~/cat.py(1)<module>() 
-> import sys 
(Pdb) 
3

Beh, questo è un tweak per la risposta di Aaron, ma penso che manca il punto in cui si desidera in modo interattivo debug ad un certo punto, giusto? Funziona ma il programma si chiude prima che tu abbia la possibilità di eseguire il debug.

(echo cont;cat bar.in) | python -m pdb foo.py 

Penso che se è possibile modificare foo.py, faccio import pdb poi al punto interessante in foo.py fare pdb.set_trace(), e basta eseguire python foo.py senza la -m pdb e dare bar.In normalmente

python foo.py < bar.in