我有这个python代码。有人能告诉我什么条件'nodedef‘和'edgedef’代表什么,什么规则需要满足的条件是正确的。
我试着用谷歌搜索答案,但我没有发现任何有用的东西。我对蟒蛇不熟悉,所以请原谅我的无知。
import numpy
import pandas
import networkx as nx
import unicodecsv as csv
path="comics-network.csv"
graph = nx.Graph(name="Characters in Comics")
with open(path, 'rb') as data:
reader = csv.reader(data)
for row in reader:
if 'nodedef' in row[0]:
handler = lambda row,G: G.add_node(row[0],TYPE=row[1])
elif 'edgedef' in row[0]:
handler = lambda row,G: G.add_edge(*row)
else:
handler=(row, graph) 发布于 2016-02-11 19:52:15
我会试着猜测,逐行评论:
# for each row in the CSV
for row in reader:
# if the first column of the row contains the string 'nodedef'
if 'nodedef' in row[0]:
# make the name "handler" point to this function (node?)
handler = lambda row,G: G.add_node(row[0],TYPE=row[1])
# else, check if it contains the string 'edgedef'
elif 'edgedef' in row[0]:
# make the name "handler" point to this function instead (edge?)
handler = lambda row,G: G.add_edge(*row)
else:
# make the name "handler" point to this tuple (root?)
handler=(row, graph)我猜想这是事后与“处理程序”一起做的事情。
https://stackoverflow.com/questions/35348562
复制相似问题