Skip to content

Instantly share code, notes, and snippets.

@minimal
Created November 27, 2012 14:52
Show Gist options
  • Save minimal/4154625 to your computer and use it in GitHub Desktop.
Save minimal/4154625 to your computer and use it in GitHub Desktop.
def trim(text, max=100):
"""Trim a string to `max` chars
"""
if len(text) > max:
return text[:max]
return text
class StatsDict(dict):
"""A dictionary that's repr trims the values of its keys so as not
to print too much
"""
tmpl = """{0}: {1},\n"""
def __repr__(self):
"""Print all keys with values trimmed
"""
text = ""
for key, value in self.iteritems():
text += self.tmpl.format(key, trim(str(value)))
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment