extracting keywords from %(keyword)s-based templates
Andrew Dalke
dalke at dalkescientific.com
Fri Aug 31 18:13:16 EDT 2001
Daniel Dittmar wrote:
>Try:
>
>class KeywordTrap:
> def __init__ (self):
> self.allwords = {}
>
> def __getitem__ (self, keyword):
> self.allwords [keyword] = 1
> return 0 # should work for %s and %d
To be more complete, this supports additional conversion types.
(Warning: untested)
class KeywordTrap:
def __init__(self):
self.allwords = {}
def __getitem__(self, keyword):
self.allwords[keyword] = 1
return self
def __int__(self): return 0
def __str__(self): return ""
def __float__(self): return 0.0
def __oct__(self): return "0"
def __hex__(self): return "0"
def __long__(self): return 1L
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list