我试图将.osm文件传递给python函数,但获取NameError

时间:2015-05-02 22:19:06

标签: python-2.7 openstreetmap

这是我的代码: -

import xml.etree.ElementTree as ET
filename= "kolkata_india.osm"

def count_tags(filename):
    tags = {}
    for event, elem in ET.iterparse(filename):
        if elem.tag in tags:
            tags[elem.tag] += 1
        else:
            tags[elem.tag] = 1

    print tags
if __name__ == "__main__":
	count_tags(filename)
这是错误信息: -

C:\Python27\Udacity\mongodb>python mapparser.py
Traceback (most recent call last):
  File "mapparser.py", line 17, in <module>
    count_tags(filename)
  File "mapparser.py", line 8, in count_tags
    filename = kolkata_india.osm
NameError: global name 'kolkata_india' is not defined

这里我做错了什么?

0 个答案:

没有答案