Alternate Syntax for dictionary elements

Aahz Maruch aahz at panix.com
Tue Jul 3 15:01:40 EDT 2001


In article <3b421046.1836046 at news.t-online.de>,
Gerson Kurz <gerson.kurz at t-online.de> wrote:
>Please consider the following:
>
>dict = { 'type' : 'button', 'id': 32, 'name' : 'some name' }
>...
>if o['type'] == 'button':
>	# do something for objects of type button
>
>Now, take a look at
>
>if o.type == 'button':
>	# do something for objects of type button

Why not just do this

class fakeDict:
    pass

dict = fakeDict()
dict.type = 'button'
if dict.type == 'button':
    ....

You can easily muck up an __init__() that uses **kwargs, too.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

"I'm not tense, i'm just terribly, terribly alert"  --unknown



More information about the Python-list mailing list