Miss Islington (bot) | b57aeac | 2018-05-14 16:57:30 -0700 | [diff] [blame] | 1 | |
2 | class X: | ||||
3 | def __init__(self, value): | ||||
4 | self.value = value | ||||
5 | def __str__(self): | ||||
6 | return str(self.value) | ||||
7 | def __format__(self, fmt): | ||||
8 | assert fmt[0] == '=' | ||||
9 | self.value = eval(fmt[1:]) | ||||
10 | return '' | ||||
11 | |||||
12 | x = X(3) | ||||
13 | print(x) | ||||
14 | f'{x:=4}' # Behold! | ||||
15 | print(x) |