Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 1.51 KB

day7.md

File metadata and controls

56 lines (48 loc) · 1.51 KB

第七天

索引

  1. pprint
data = [
    (1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),
    (2, {'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H',
         'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L'}),
    (3, ['m', 'n']),
    (4, ['o', 'p', 'q']),
    (5, ['r', 's', 't''u', 'v', 'x', 'y', 'z']),
]
from pprint import pprint

print('PRINT:')
print(data)
print()
print('PPRINT:')
pprint(data)
  1. class with repr
from pprint import pprint


class node:

    def __init__(self, name, contents=[]):
        self.name = name
        self.contents = contents[:]

    def __repr__(self):
        return (
            'node(' + repr(self.name) + ', ' +
            repr(self.contents) + ')'
        )


trees = [
    node('node-1'),
    node('node-2', [node('node-2-1')]),
    node('node-3', [node('node-3-1')]),
]
pprint(trees)
  1. pprint(data, depth=1), pprint(data, depth=2) 可以定义深度
  2. pprint(data, width=width) 可以定义宽度