osm 文件,解析,即使清除元素也会出现内存错误。

osm file, parsing, memory error even with clearing elements.

我想获取一个 osm 文件,清理它,然后将其另存为 json 文件。 xml 文件大约 1 GB。

def audit():
    osm_file = open('c:\Users\Stephan\Downloads\los-angeles_california.osm', "r")
    with open('lala.txt', 'w') as outfile:
        for event, elem in ET.iterparse(osm_file, events=("start",)):   
            if elem.tag == "node" or elem.tag == "way":
                json.dump(shape_element(elem),outfile)
                elem.clear()  
audit()

尽管我使用 elm.clear(),但我仍然遇到内存错误。有人知道为什么吗?

osm_file = open('c:\Users\Stephan\Downloads\los-angeles_california.osm', "wr")

如果你想清理它,它应该是可写的