I am generating pages from some sensor data.  Sometimes, if the sensors 
glitch, instead of a number, there will be a 'NaN' in the number field.  

Since I'm trying to keep my display logic separate, I'm doing things like 
this:

${'%.0f' % ms2mph(lr.windSpeedAvg)}

in the template.  Which is fine, until a value such as NaN comes along, and 
then an exception is thrown.  I have a couple of ideas, neither of which I 
know how to do.

1. Overload the string formatting, and accept strings or None and 
return 'N/A'.  Is there anyway to overload that operation?

2. Create a formatting function.  This I could do, but doing something like 
this:

x = 1

'%.xf' % ms2mph(lr.windSpeedAvg)

doesn't produce the desired results.  Any suggestions?  I suppose I could do 
an if/then tree since the we'd only be doing %.0f, %.1f, and %2f, basically.

Did I not google the right phrase? :)

j

-- 
Joshua Kugler                           
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE
PO Box 80086 -- Fairbanks, AK 99708 -- Ph: 907-456-5581 Fax: 907-456-3111

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
kid-template-discuss mailing list
kid-template-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kid-template-discuss

Reply via email to