| Conditions | 7 |
| Total Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | |||
| 5 | def StarTuple(name, named_fields, elements): |
||
| 6 | named_tuple = collections.namedtuple(name, named_fields) |
||
| 7 | |||
| 8 | def this_pack(self): |
||
| 9 | packed = bytes() |
||
| 10 | for key, value in self.__elements.items(): |
||
| 11 | packed += value.pack(self._asdict()) |
||
| 12 | |||
| 13 | return packed |
||
| 14 | |||
| 15 | def this_str(self): |
||
| 16 | import pprint |
||
| 17 | fmt = 'StarTuple: <{0}>\n'.format(str(name)) |
||
| 18 | |||
| 19 | len_of_keys = 0 |
||
| 20 | for key in self._asdict().keys(): |
||
| 21 | if len(key) > len_of_keys: |
||
| 22 | len_of_keys = len(key) |
||
| 23 | |||
| 24 | for key, value in self._asdict().items(): |
||
| 25 | fmt += (' {key:%d}: {value}\n' % len_of_keys).format( |
||
| 26 | key=key, |
||
| 27 | value=pprint.pformat(value, width=150), |
||
| 28 | ) |
||
| 29 | |||
| 30 | return fmt |
||
| 31 | |||
| 32 | named_tuple.pack = this_pack |
||
| 33 | named_tuple.__str__ = this_str |
||
| 34 | named_tuple.__elements = elements |
||
| 35 | |||
| 36 | return named_tuple |
||
| 37 |
Prefixing a member variable
_is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class: