Print formatted tuple in Python

Print formatted tuple in Python

As we know, we can print formatted JSON string with the following JavaScript code:

1
console.log(JSON.stringify(object, null, 4)); // indent 4 spaces

In Python, we can do the same thing with ffprint, which is a built-in module of Python.

Talk is cheap, show me the code 😜

1
2
3
4
5
6
7
8
import yaml
from pprint import pprint

with open('../config.yml') as stream:
try:
pprint(yaml.safe_load(stream))
except yaml.YAMLError as ex:
print(ex)

Result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{'batch_size': 8,
'bbox_output': True,
'bbox_output_path': 'tracking_result',
'context_amount': 0.5,
'examplar_size': 127,
'gamma': 0.8685,
'instance_size': 255,
'label_weight_method': 'balanced',
'lr': 0.01,
'momentum': 0.9,
'net': 'SiamFC_50_model.pth',
'net_base_path': '/Train/model',
'num_epoch': 50,
'num_pairs': 53200,
'num_scale': 3,
'pos_pair_range': 100,
'rNeg': 0,
'rPos': 16,
'response_UP': 16,
'scale_LR': 0.59,
'scale_max': 5,
'scale_min': 0.2,
'scale_penalty': 0.9745,
'scale_step': 1.0375,
'score_size': 17,
'seq_base_path': '/computervision/datasets/OTB100',
'step_size': 1,
'stride': 8,
'sub_mean': 0,
'train_num_workers': 12,
'val_num_workers': 8,
'val_ratio': 0.1,
'video': 'Lemming',
'visualization': False,
'w_influence': 0.176,
'weight_decay': 0.0005,
'windowing': 'cosine'}