String handling and the percent operator

Justin Azoff justin.azoff at gmail.com
Thu Jul 13 20:28:32 EDT 2006


Tom Plunket wrote:
> 	boilerplate = \
> """
[big string]
> """
>
> 	return boilerplate % ((module,) * 3)
>
> My question is, I don't like hardcoding the number of times that the
> module name should be repeated in the two return functions.  Is there
> an straight forward (inline-appropriate) way to count the number of
> '%s'es in the 'boilerplate' strings?  ...or maybe a different and more
> Pythonic way to do this?  (Maybe I could somehow use generators?)
>
> thx.
> -tom!

Of course..

>>> stuff = {'lang': 'python', 'page': 'typesseq-strings.html'}
>>> print """I should read the %(lang)s documentation at
... http://docs.%(lang)s.org/lib/%(page)s""" % stuff
I should read the python documentation at
http://docs.python.org/lib/typesseq-strings.html


-- 
- Justin




More information about the Python-list mailing list