ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] Help with vars()
by Steven Burr other posts by this author
Aug 11 2001 8:18PM messages near this date
Re: [Tutor] Help with vars() | Re: [Tutor] Help with vars()
On Saturday, August 11, 2001, at 03:08 AM, Charlie Clark wrote:

> > 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?

I'm new to Python myself, so I'm not certain about the terminology and 
would welcome an explanation from one of the gurus.

But first allow me to embarrass myself.  Based on the context in which 
I've seen the term "wrapper" used, I had been thinking that it meant an 
object that includes and extends, or allows easier access to, another 
object.  So for example, if you wrote a class using UserDict and added 
new methods for manipulating the dictionary, that would be a dictionary 
"wrapper."  In 2.2, we'll be able to write class wrappers for 
dictionaries and lists without using UserDict or UserList.

vars(), as I understand it, is a function that returns the __dict__ 
object for any object that contains one.  Since a class instance 
includes a table of its variables and their values, and the table either 
is or can be translated into a dictionary (something else I'm uncertain 
about), calling vars on the instance yields the above result.  I would 
not have thought of that as being a "wrapper," but I could very easily 
be all wet.

it-wouldn't-be-the-first-time'ly yours, sburrious

_______________________________________________
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved