2010-08-23 95 views
1

目前我正面临以下问题:需要帮助与NetworkX

我有一个脚本,通过包含文档的特定目录进行搜索。每个文档都在文件名中分配一个数字。在每个文档中都有代表另一个文档(文件名)的数字。我怎样才能创建一个网页,显示什么文件导致什么?

任何帮助,将理解的是,得益于

回答

2

这是一个有向图的一个典型例子。您应该阅读NetworkX tutorial以更好地了解如何使用它们;基本上,您需要添加所有节点(点),在这种情况下文件编号,然后在它们之间添加边。

import os 
import networkx as nx 

g = nx.DiGraph() 
for filename in os.listdir(<dir>): 
    # do something to filename to get the number 
    g.add_node(<number>) 

for filename in os.listdir(<dir>): 
    # do something to filename to get the source 
    with open(filename) as theFile: 
     # do something to theFile to get the targets 
     for target in <targets>: 
      g.add_edge(<source>, <target>) 

import matplotlib.pyplot as plt 
nx.draw(g) 
+0

好的,谢谢,生病了试试看 – user428370 2010-08-25 11:52:42