문제

matrix = [ [1,2,3], [4,5,6], [7,8,9] ]
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(matrix)

This does not pretty print. It ugly prints.

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

What gives??

도움이 되었습니까?

해결책

Its because the length of the printed array when on one line is less than the default width of 80. You might want to review the documentation for pprint.

For example, if we do:

matrix = [ [1,2,3], [4,5,6], [7,8,9] ]
import pprint
pp = pprint.PrettyPrinter(indent=4,width=20)
pp.pprint(matrix)

We get:

[   [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top