Re: [Tutor] Help with vars()
by Charlie Clark other posts by this author
Aug 11 2001 10:08AM messages near this date
Re: [Tutor] Help with vars()
|
Re: [Tutor] Help with vars()
> 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
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Charlie Clark
Danny Yoo
Steven Burr
Charlie Clark
Steven Burr
Charlie Clark
lonetwin
Charlie Clark
Steven Burr
|