[Tutor] Help with vars()

Charlie Clark Charlie Clark <charlie@begeistert.org>
Sat, 11 Aug 2001 12:08:54 +0200


>But if you really want to use vars, you can:
>
> >>> class Blank:
>...     pass
>...
> >>> article = Blank()
> >>> article.headline = "Horoscope for Peter"
> >>> article.text = "Things are looking up!"
> >>> article.asterisk = "Aquarius"
> >>> print "\n%(headline)s* \n\n%(text)s\n----\n*%(asterisk)s" % 
>vars(article)
>
>Horoscope for Peter*
>
>Things are looking up!
>----
>*Aquarius
so vars() acts like a dictionary type wrapper and as such isn't necessary for 
dictionaries themselves?

article.headline in a class is equivalent to article['headline'] in a 
dictionary in this case? Just different ways of storing and retrieving the 
same information. mm, can see the drive to unify types and classes to tidy 
this up.

I'm actually storing a dictionary in a class, returning it in a function and 
assigning the return to a new variable to do further work on. Can probably 
improve on this once I get better at the whole OOP thing.

Thanx

Charlie