spir wrote:
> 
> 
> What you're looking for is a dictionary...
> s = {"cheese":"Brie", "country":"France", ...}
> 
> Or maybe a kind of object type that works ~ like a dict, but with object
> syntax (get rid of {} and "" for keys). Example:
> 
> class Stuff(object):
>       def __iter__(self):
>               return iter(self.__dict__.items())
>       def items(self):
>               return self.__dict__
> 
> stuff = Stuff()
> stuff.cheese="Brie"
> stuff.country="France"
> print stuff.cheese, stuff.country
> print stuff.items()
> for st in stuff:
>       print "   ", st
> ==>
> Brie France
> {'cheese': 'Brie', 'country': 'France'}
>     ('cheese', 'Brie')
>     ('country', 'France')
> 
> 
> Denis
> ------
> la vita e estrany
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


Denis,

This is working, but what would be ideal is to have 'best of both' worlds.
Is there a way to combine this class with a dict, so that I can do both:

%S = Stuff()
%S['this'] = 'is great'

and then:

%S.this
'is great'

But also, be able to change it so that:
%S.this = 'is even better'

and yet still:
%S['this']
'is even better'

Thanks!

-- 
View this message in context: 
http://www.nabble.com/creating-a-dict-like-class---asigning-variables...-this-one-may-take-some-thought--%29-tp23759398p24321728.html
Sent from the Python - tutor mailing list archive at Nabble.com.

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to