[Tutor] Help with vars()
Charlie Clark <email@example.com>
Sat, 11 Aug 2001 12:08:54 +0200
>But if you really want to use vars, you can:
> >>> class Blank:
> >>> 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" %
>Horoscope for Peter*
>Things are looking up!
so vars() acts like a dictionary type wrapper and as such isn't necessary for
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
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.