__init__(self,
vocab,
canonize=False,
allow_other=False)
(Constructor)
| source code
|
For example:
>>> d = ['foo', ['bar', 'baz'], 'quux']
>>> v = Vocab(d)
>>> v('foo')
'foo'
>>> v('bar')
'baz'
>>> v('corge')
Traceback (most recent call last):
...
ValueError: 'corge' is not a member of ['quux', 'foo', 'bar']
>>> v = Vocab(d, allow_other=True)
>>> v('corge')
'corge'
>>> v = Vocab(d, canonize=True, allow_other=True)
>>> v('foo')
'FOO'
>>> v('bar')
'BAZ'
>>> v('corge')
'CORGE'
- Parameters:
vocab - a sequence of permitted values or value pairs (input and
transformation)
canonize (bool) - should all values be transformed to a canonical form
allow_other (bool) - allow non-listed values
- Returns:
- the original value, mapped & canonized if supplied and requested
- Overrides:
object.__init__
|