[英]Python parsing GPRMC string with CSV
I have GPRMC string which consists of 12 comma delimited values. 我有由12个逗号分隔值组成的GPRMC字符串。 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: 例如:
>>> gprmc = "$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.