kzahel
kzahel

Reputation: 2785

Print \n newline as actual newline in python pdb

When I am in pdb and I have a large string, sometimes I'd like to print it out with newlines as actual newlines, instead of seeing them as \n in the terminal.

(Pdb) p large_string
"very large string with newline\nanother line in the large string\n\netc\n"

I'd rather see

(Pdb) printwithnewline large_string
"very large string with newline
another line in the large string

etc
"

Any tips?

Upvotes: 4

Views: 1997

Answers (3)

Uri Barkai
Uri Barkai

Reputation: 90

You can prefix any Python command with '!', so this will also work for Python 2.x:

!print large_string

Upvotes: 0

Thane Plummer
Thane Plummer

Reputation: 10238

If you use Python 2.x you can import the print function:

from __future__ import print_function

(Pdb) print(large_string)
very large string with newline
another line in the large string

Upvotes: 2

Bryan Oakley
Bryan Oakley

Reputation: 386020

just call the normal print function:

(Pdb) print(large_string)
very large string with newline
another line in the large string

etc
(Pdb)

Upvotes: 6

Related Questions