Overview

What makes an ObDict tick

If you are a user of any kind of Python console that sports Tab completion, you may have come to appreciate automatic attribute listing. This is, perhaps, the most immediately rewarding part of using ObDict. To begin magical experience, follow by example.

Core Features

This type wraps a given dict-like object for dotted attribute access of keys.:

>>> import obdict
>>> obby = obdict.ObDict({'zoobaz': 'pantaloon', 'skidz': {'fashizzle': 9000, 'hambones': {'bork': ['-ing', '-ham']}, 'boo': 'ghosty'}})
>>> obby.zoobaz
'pantaloon'
>>> obby.skidz.fashizzle
9000
>>> obby.skidz.hambones.bork
['-ing', '-ham']

Repr friendly

The repr() of this type is a true repr, as it provides an eval-able string.:

>>> obby
ObDict({'skidz': ObDict({'fashizzle': 9000, 'hambones': ObDict({'bork': ['-ing', '-ham']}), 'boo': 'ghosty'}), 'zoobaz': 'pantaloon'})

Attribute name mangling

Because of the (very sensible) restrictions on attribute naming in Python, dict keys that are reserved keywords, contain restricted characters, or begin with digits will be sensibly mangled with a fill character of '_'.:

>>> yucky_dict = {'assert': 'cheezmeltz', 'print': 'coupon', '1992': 'best year ever'}
>>> mangle_ob = obdict.ObDict(yucky_dict)
>>> mangle_ob
ObDict({'assert_': 'cheezmeltz', '_1992': 'best year ever', 'print_': 'coupon'})
>>> mangle_ob.keys()
['assert_', '_1992', 'print_']
>>> mangle_ob.print_
'coupon'
>>> mangle_ob.assert_
'cheezmeltz'
>>> mangle_ob._1992
'best year ever'

Why distribute a type?

The IPython shell is awesome, what with its wonderful tab completion of dot-accessible objects. ObDict helps with that...

Who made this awesome?

  • Dan Buch got cheesed off about something at work and started ObDict.
  • Mike Crute helped ObDict get dressed up for the ball.

Contributions warmly welcomed, clothed, and fed.