Trigraph Idiom - Original?

Jeff Winkler winkler1 at gmail.com
Wed Apr 27 19:26:02 EDT 2005


I've come up with a trigraph idiom, am curious if it's been done before
(probably). I like to use trigraphs occasionally.

Scenario: I'm doing an RSS->Javascript conversion for our intranet. I'd
like to use different CSS class if a post is new. Code:

hoursOld=abs(time.time()-time.mktime(i.modified_parsed))/3600
cssClass=['rssLink','rssLinkNew'][hoursOld<12]
entry='<a href="%s" class="%s" target="detail">%s</a>' %
(cssClass,i['link'],i['title'])

So, ['rssLink','rssLinkNew'] is index by boolean value- False:0, or
True:1.

I realize many will find this hideous, but 3 lines of code to do
something simple seems equally bad. Thoughts? Is there a better way?

- Jeff




More information about the Python-list mailing list