python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfa / util / printable.py
1 # yet another way to display records...
2 def beginning(foo, size=15):
3     full = "%s" % foo
4     if len(full) <= size:
5         return full
6     return full[:size - 3] + '...'
7
8
9 def printable(record_s):
10     # a list of records :
11     if isinstance(record_s, list):
12         return "[" + "\n".join([printable(r) for r in record_s]) + "]"
13     if isinstance(record_s, dict):
14         return "{" + " , ".join(["%s:%s" % (k, beginning(v)) for k, v in record_s.items()]) + "}"
15     if isinstance(record_s, str):
16         return record_s
17     return "unprintable [[%s]]" % record_s