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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to