Try: class KeywordTrap: def __init__ (self): self.allwords = {} def __getitem__ (self, keyword): self.allwords [keyword] = 1 return 0 # should work for %s and %d trap = KeywordTrap () formatstring % trap print trap.allwords.keys () Daniel