Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下列表(nodes):
nodes
nodeID, x, y, z=row
我想找到row[0]==nodeAID.
row[0]==nodeAID
我的代码是:
nindF=[line[0].index(nodeAID) for line in nodes]
但它给了我错误:TypeError: expected a character buffer object
TypeError: expected a character buffer object
nindF = [index for index, line in enumerate(nodes) if line[0].find(nodeAID) >= 0]
这将返回以 nodeAID 开头的所有行的索引列表。如果您只关心以 nodeAID 开头的第一行的索引,那么:
nindF = [index for index, line in enumerate(nodes) if line[0].find(nodeAID) >= 0][0]