AttributeError:'元组'对象没有属性' low_connectivity_nodes'

时间:2017-12-07 20:46:34

标签: python python-2.7 attributes tuples

我正在尝试关注Pandana网络辅助功能演示' Github回购(https://github.com/gboeing/urban-data-science/blob/master/20-Accessibility-Walkability/pandana-accessibility-demo-full.ipynb)。

到目前为止,复制和粘贴代码时一切都很好,但是当我运行这个时出现了一个问题:

start_time = time.time()
if os.path.isfile(net_filename):
    # if a street network file already exists, just load the dataset from that
    network = pandana.network.Network.from_hdf5(net_filename)
    method = 'loaded from HDF5'
else:
    # otherwise, query the OSM API for the street network within the specified bounding box
    network = osm.network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3])
    method = 'downloaded from OSM'

    # identify nodes that are connected to fewer than some threshold of other nodes within a given distance
    lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')
    network.save_hdf5(net_filename, rm_nodes=lcn) #remove low-connectivity nodes and save to h5

print('Network with {:,} nodes {} in {:,.2f} secs'.format(len(network.node_ids), method, time.time()-start_time))

这是我得到的错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-7-693cbbc8dc72> in <module>()
     10 
     11     # identify nodes that are connected to fewer than some threshold of other nodes within a given distance
---> 12     lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')
     13     network.save_hdf5(net_filename, rm_nodes=lcn) #remove low-connectivity nodes and save to h5
     14 

AttributeError: 'tuple' object has no attribute 'low_connectivity_nodes'

1 个答案:

答案 0 :(得分:0)

您可以通过以下操作解决此错误

network = osm.network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3])
network=pandana.Network(network[0]["x"],network[0]["y"], network[1]["from"], network[1]["to"],
                 network[1][["distance"]])
lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')
network.save_hdf5(net_filename, rm_nodes=lcn) #remove low-connectivity nodes and save to h5