[Tutor] using a dictionary??

PFraterdeus peterf at mac.com
Thu Apr 21 03:56:25 CEST 2005


Here'a little py script for a plone page template...
I just want to translate the 'key' (organicnews) to a 'value' (Organics in the
News), for presentation purposes. (the key, of course, is in the URL request)


db = request.db

if db=="organicnews":  
 print "%s" % html_quote('Organics in the News')
elif db=="ovnews":
 print "%s" % html_quote('Our Stuff in the News')
elif db=="pressreleases":
 print "%s" % html_quote('Press Releases')
else:
 print "Unknown News Database!",
 print "%s" % db
return printed

This script works fine as is, no problem... BUT


I know there's a proper way to do this with a tuple, or something :)
For the three values, it's not a problem, but if I want to scale up to many, I
imagine the dictionary is the way to go...

Thanks for hints on a proper pythonesque and elegant syntax for this pattern!

Ciao
Peter





More information about the Tutor mailing list