skip to navigation
skip to content

Not Logged In

wardrobe 0.1

Stack-based datastructures: StackedDict.

wardrobe is a Python project about datastructures to manage contexts. It currently provides one class: StackedDict.

StackedDict is a dictionary-like object with additional methods to save the current state (commit) and restore it (reset).

Example:

>>> from wardrobe import StackedDict
>>> clark = StackedDict(top='blue bodysuit', bottom='red underpants',
...                     sex_appeal=True)
>>> clark['bottom']
'red underpants'
>>> clark['friend'] = 'Lois'
>>> dict(clark) == {'top': 'blue bodysuit',
...                 'bottom': 'red underpants',
...                 'friend': 'Lois',
...                 'sex_appeal': True}
True
>>> clark.commit()  # doctest: +ELLIPSIS
<wardrobe.stackeddict.StackedDict object at 0x...>
>>> clark.update({'top': 'shirt', 'bottom': 'jeans', 'head': 'glasses'})
>>> del clark['sex_appeal']
>>> dict(clark) == {'top': 'shirt',
...                 'bottom': 'jeans',
...                 'head': 'glasses',
...                 'friend': 'Lois'}
True
>>> clark.reset()  # doctest: +ELLIPSIS
<wardrobe.stackeddict.StackedDict object at 0x...>
>>> dict(clark) == {'top': 'blue bodysuit',
...                 'bottom': 'red underpants',
...                 'friend': 'Lois',
...                 'sex_appeal': True}
True

wardrobe.StackedDict is useful to create context objects, like Django's django.template.context:Context objects.

 
File Type Py Version Uploaded on Size
wardrobe-0.1.zip (md5) Source 2012-07-26 11KB
  • Downloads (All Versions):
  • 7 downloads in the last day
  • 17 downloads in the last week
  • 134 downloads in the last month