I've got a python script that takes input on stdin. I'd like to drop into IPython.embed(), like this:
for filepath in sys.stdin:
dir = os.path.basename(filepath)
...
IPython.embed()
I then invoke the script like this:
find . -type f | thescript.py
The problem is that IPython uses stdin for the interactive console, so the first thing it sees are the remaining pipe data. Then, the pipe closes and the the terminal exits.
Is there a way to debug a script that uses stdin with ipython?
You could read your stdin input into a list first, then reset stdin:
stdin_list = list(sys.stdin)
sys.stdin = open('/dev/tty')
for filepath in stdin_list:
dir = os.path.basename(filepath)
...
IPython.embed()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With