items = {"NAME":{"label":"名称","fieldName":"NAME"},"ADDRESS":{"label":"地址","fieldName":"ADDRESS"},"LON":{"label":"经度","fieldName":"LON"},"LAT":{"label":"纬度","fieldName":"LAT"},"SOURCE":{"label":"数据来源","fieldName":"SOURCE"},"CITYCODE":{"label":"城市代码","fieldName":"CITYCODE"},"PRODATE":{"label":"处理日期","fieldName":"PRODATE"}} ''' #遍历列表,读要素 for x in items: print "fieldName1 = %s" % x ''' #用enumerate函数遍历list for i,j in enumerate(items): print "fieldName%d = %s" % (i,j)
最终得到这样的结果
fieldName0 = CITYCODE fieldName1 = NAME fieldName2 = LON fieldName3 = PRODATE fieldName4 = SOURCE fieldName5 = ADDRESS fieldName6 = LAT
有时,因为输出需要,字段必须保留""。所以,在双引号前面加个转义符 ,即反斜杠。如"Hello "W “orld”,会输出 Hello "W"orld。
例如上面的语句
# -*- coding: utf-8 -*- items = {"NAME":{"label":"名称","fieldName":"NAME"},"ADDRESS":{"label":"地址","fieldName":"ADDRESS"},"LON":{"label":"经度","fieldName":"LON"},"LAT":{"label":"纬度","fieldName":"LAT"},"SOURCE":{"label":"数据来源","fieldName":"SOURCE"},"CITYCODE":{"label":"城市代码","fieldName":"CITYCODE"},"PRODATE":{"label":"处理日期","fieldName":"PRODATE"}} ''' #遍历列表,读要素 for x in items: print "fieldName1 = %s" % x ''' #用enumerate函数遍历list for i,j in enumerate(items): print "fieldName%d = "%s"" % (i,j)
输出结果为
fieldName0 = "CITYCODE" fieldName1 = "NAME" fieldName2 = "LON" fieldName3 = "PRODATE" fieldName4 = "SOURCE" fieldName5 = "ADDRESS" fieldName6 = "LAT"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)