Bullet proof passing numeric values from NMEA data stream.

Doug Gray doug at localhost.localdomain
Tue Mar 20 13:09:29 CET 2007


Folks,
I am looking for a fast but most importantly a bullet proof method to pass
and NMEA data stream (GPS output) ascii numeric strings. The best I can
offer is:

def fint(a):
 try: return int(float(a))
 except: return 0

The reason for this is the quality of the data from the huge variety of
GPS units available varies considerably.  Some units do not follow the
standard and I want to pass the data as best I can without hanging the
code for an oddball data value.

Can anyone suggest better?

For example, each of the following throw the exception so do not return
the correct value:

int('00.')
int(' 00.')
float('-  00')
float(' -  00')
float(' -  00')
float(' -  00.')
float('-  00.')
float('-  10.')
float('- 10.')
float('- 10.')
int('- 10.')
int('- 10.')
float('- 10.')
int('1.0')

Also, why should I consider the string module?  Is it faster/better?

TIA,
Doug



More information about the Python-list mailing list