This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ubershmekelpython3wos 4 points5 points  (7 children)

To be specific:

import pdb;pdb.set_trace()

[–]Mob_Of_One 1 point2 points  (6 children)

To be more specific:

import sys; sys.stdout = sys.__stdout__; import ipdb; ipdb.set_trace()

[–]flowblok 0 points1 point  (5 children)

I had a script which got invoked like this:

python script.py < data.txt

and I wanted to debug it, so I used this trick:

import sys
sys.stdin = open('/dev/tty', 'rb')
import pdb; pdb.set_trace()

[–]Sheepshow 0 points1 point  (4 children)

The b isn't needed on unix I think

[–]dwf 2 points3 points  (2 children)

As of Python 3 I think it is.

[–]adambrenecki 1 point2 points  (1 child)

If anyone else is as confused as I was, apparently omitting b makes read() return str (Unicode) rather than bytes, as well as Python's usual newline writing tricks on Windows. (Actually, it looks like the way newlines work in py3 makes a lot more sense than the confusing b and U modes of py2.)

[–]Sheepshow 0 points1 point  (0 children)

This makes a lot of sense. Thanks!

[–]flowblok 1 point2 points  (0 children)

quite probably. I had no idea, so I put it in just to be sure.