A Python class that only prints unique files. Useful for debugging inner loops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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