wardrobe’s documentation

wardrobe is a Python project that provides a stack-based datastructure: StackedDict.

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

>>> 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()  
<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()  
<wardrobe.stackeddict.StackedDict object at 0x...>
>>> dict(clark) == {'top': 'blue bodysuit',
...                 'bottom': 'red underpants',
...                 'friend': 'Lois',
...                 'sex_appeal': True}
True

Indices and tables

Project Versions

Table Of Contents

Next topic

Installation

This Page