I have GPRMC string which consists of 12 comma delimited values. When I run my code it does in fact split the commas, but it prints each character in the comma separated value on a new line - instead of grouping all characters in between a comma together.
For example:
>>> g开发者_Go百科prmc = "$GPRMC,1244.0,A,3111.334505,N,90729.3111898,W,1.2,,020811,,,A*55"
>>> gprmcReader = csv.reader(gprmc)
>>> for val in gprmcReader:
print val
['$']
['G']
['P']
['R']
['M']
['C']
['', '']
['1']
['2']
['4']
['4']
['.']
['0']
['', '']
['A']
['', '']
['3']
['1']
['1']
['1']
['.']
['3']
['3']
['4']
['5']
['0']
['5']
['', '']
Try this:
import csv
reader = csv.reader(open(filename, 'r'))
for row in reader:
if row and row[0].strip() == '$GPRMC':
for val in row:
print val
print "_____________________"
To check my code i have created file that contains one row with the following text:
$GPRMC,135005.0,A,3526.351705,N,90729.337898,W,1.2,,020811,,,A*55
Executing my code prints me:
$GPRMC
135005.0
A
3526.351705
N
90729.337898
W
1.2
020811
A*55
精彩评论