pretty print python code example
Example 1: prettytable python
from prettytable import PrettyTable
PTables = PrettyTable()
PTables = PrettyTable()
PTables.field_names = ["Selection No.", "Weapon Name", "Damage"]
PTables.add_row(["0", "Fist", "1 dp"])
PTables.add_row(["1", "Knuckle Busters", "2.5 dp"])
PTables.add_row(["2", "Cheap Knife", "5 dp"])
PTables.add_row(["3", "Wooden Baton", "6 dp"])
print(PTables)
Example 2: python print dict pretty
>>> import json
>>> print json.dumps({'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}},
... sort_keys=True, indent=4)
{
"a": 2,
"b": {
"x": 3,
"y": {
"t1": 4,
"t2": 5
}
}
}
Example 3: python pretty print
import pprint
student_dict = {'Name': 'Tusar', 'Class': 'XII',
'Address': {'FLAT ':1308, 'BLOCK ':'A', 'LANE ':2, 'CITY ': 'HYD'}}
print student_dict
print "\n"
print "***With Pretty Print***"
print "-----------------------"
pprint.pprint(student_dict,width=-1)