【发布时间】:2020-01-10 07:49:39
【问题描述】:
假设我有一个 python 程序,我想执行此操作
grep "username" accounts.txt
1 行
accounts.txt 与我的 py 文件位于同一文件夹中。我知道在 C 中有一些像 System(grep "username" accounts.txt) 这样的函数,并且想知道在 python 中是否有类似的东西。通常python读取accounts.txt太慢,因为它是一个大文件。但是在 bash 或 linux 中它要快得多,所以想知道我是否可以使用 bash 来查找用户名行,然后 python 将其打印出来。
如果没有,什么是集成大型用户名文件的有效方法,我可以在我的 python 代码中调用该文件以打印出与之关联的行。
【问题讨论】:
-
要进行系统调用,请查看stackoverflow.com/questions/89228/…
标签: python bash python-2.7 window