Skip to content

Instantly share code, notes, and snippets.

@markwatson
Created March 8, 2012 18:29
Show Gist options
  • Save markwatson/2002519 to your computer and use it in GitHub Desktop.
Save markwatson/2002519 to your computer and use it in GitHub Desktop.
A Python class that only prints unique files. Useful for debugging inner loops.
class PrintUnique(object):
"""
A class that keeps track of what it has printed to stdout and won't
print anything twice.
"""
printed = set()
@classmethod
def write(cls, s):
"""
Prints a string if it hasn't been printed before.
"""
if s not in cls.printed:
cls.printed.add(s)
print s
@classmethod
def reset(cls):
cls.printed = set()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment