[Tutor] Help with vars()

lonetwin lonetwin <lonetwin@yahoo.com>
Fri, 10 Aug 2001 15:31:12 +0530 (IST)


On Fri, 10 Aug 2001, Charlie Clark wrote:

>>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
>>###
>>
>>
>>Note: the string formatting above requires us to put the variables in the
>>'%(foo)s' sorta format --- the trailing 's' doesn't stand for plurality,
>>but for 'string'ality.
>>
>>Hope this helps!
>Yes, it does but it's confusing and isn't explicit in the documentation. 
>%s(name) or %d(name) would make more sense to me.

 Ehe....I didn't know about the %(foo)[s|d|whatever] format string, all this
 time I was doing things like (for the example above):

 insert = "%s, %s, %s" % (articles['headline'], articles['text'], articles['sternzeichen'])

 Now, I'm curious, is this a *BAD THING* to do ???

Peace
Steve
-----------------------------------------
bug, n:
		A son of a glitch.
-----------------------------------------