python取文件的指定行
QQ群:397745473
一堆文件,想把这些文件的第2行全部弄出来,用python实现就很方便了
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
import os import glob import linecache
PATH = '/www/wwwroot/zmy.xd10086.com/zmy/content/chinese/posts'
for file in glob.glob(PATH + os.sep + '*.md'): text = linecache.getline(file, 2) print(text)
|
Python中的read(),readline(),readlines()区别与用法
参考:https://www.jianshu.com/p/a672f39287c4
QQ群:397745473