Style question: Nicknames for deeply nested objects

rantingrick rantingrick at gmail.com
Sun Jan 30 13:35:37 EST 2011


On Jan 30, 12:23 pm, Stephen Hansen <me+list/pyt... at ixokai.io> wrote:

> --- start
> from contextlib import contextmanager
>
> class Item(object): pass
>
> deeply = Item()
> deeply.nested = Item()
> deeply.nested.thing = Item()
>
> @contextmanager
> def my(thing):
>     yield thing
>
> with my(deeply.nested.thing) as o:
>     o.hello = 1
>
> print deeply.nested.thing.hello
> --- end

Well congratulations Stephen, you win the obfuscation prize of the
year!



More information about the Python-list mailing list