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:20AM messages near this date
Re: [Tutor] Help with vars() | Re: [Tutor] Help with vars()
On Friday, August 10, 2001, at 02:18 AM, Danny Yoo wrote:

>  On Fri, 10 Aug 2001, Charlie Clark wrote:

> 

> > I'd like to use vars() in together with a database command (Marc André

> > Lemburg's mxODBC) but seem to have missed something.

> >

> > articles = {'sternzeichen': 'Wassermann', 'text': 'Es wird besser',

> > 'headline': 'Horoskop f\xc3\xbcr Peter'}

> >

> > when I use

> > insert = "%headline, %text, %sternzeichen" %vars(articles)

> 

[snip]
>  Start screaming.  *grin* We won't need to call vars() at all: we can 

>  just

>  do the interpolation directly with the dictionary that's in our hands:

> 

>  ###

> >>> insert = "%(headline)s, %(text)s, %(sternzeichen)s" % articles

> >>> print insert

>  Horoskop fr Peter, Es wird besser, Wassermann

>  ###


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

_______________________________________________
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