需要列表的问题
我当前面临的问题来自以下场景。我有一个脚本,它运行命令行程序来查找特定文件夹中特定扩展名的所有文件,我们将这些文件称为文件 A。脚本的另一部分通过每个文件运行 grep 命令来查找文件 A 中的文件名。存储文件 A 中且仅存储文件 A 中的文件名的最佳方法,我该如何实现?谢谢
The current issue im facing is comes from the following scenario. I have a script that runs a commandline program to find all files of a certain extension within an specific folder, lets call these files File A. Another section of the script runs a grep command through each file for filenames within File A. What would be the best method to store what filenames are in File A and only File A, and how could I achieve it? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我看到你是问上一个问题的人!为什么要开新的呢?
最近有一个关于这个确切问题的问题——您正在建模的结构是一个有向图。请使用 Python 的
networkx
包。如果您要对数据进行一些后处理,那么使用此包是一个好主意。但是,对于简单的情况,您可以创建自己的数据结构。这是使用图的邻接列表表示的示例;使用邻接矩阵代替并不困难。这将为您提供一个文件名字典 ->由该文件链接的文件。
EDIT: I see you were the one who asked the previous question! Why open a new one?
There was a recent question on this exact problem -- the structure you are modelling is a directed graph. See my answer to that question, using Python's
networkx
package. Using this package is a good idea if you are going to do some post-processing of the data. However, for simple situations, you could make your own data structure. Here is a sample using an adjacency list representation of a graph; it is not difficult to use an adjacency matrix instead.This will give you a dictionary of filename -> files linked by that file.