从下面运行python代码时出现此错误
'dict_items' object does not support indexing
https://github.com/commodo/geonames-dump-to-sqlite/blob/master/geonames_dump_to_sqlite.py
代码所做的是从地理名称中获取文件并将结果放入 sqlite 数据库中。
它运行良好,直到创建表
def create_tables(cur):
'''
Create empty tables which will be populated later.
'''
for table_name in TABLE_MAPPINGS.values():
cur.execute('DROP TABLE IF EXISTS %s' % table_name)
table_fields = [ "%s %s" % table_field.listitems()[0] for table_field in TABLE_FIELDS ]
cur.execute('CREATE TABLE %s (%s)' % (table_name, ','.join(table_fields)))
错误细节:
line 111, in <listcomp>
table_fields = [ "%s %s" % table_field.items()[0] for table_field in TABLE_FIELDS ]
TypeError: 'dict_items' object does not support indexing