标签:rom ica The example orm xpath rod reader read
from pathlib import Path
import os
import re
pathName=‘./‘
fnLst=list(filter(lambda x:not x.is_dir(),Path(pathName).glob(‘**/*.txt‘)))
print(fnLst)
for fn in fnLst:
with open(fn) as f:
print()
print(fn)
for line in f:
for word in re.findall(r‘\w+‘, line):
print(word,end="|")
输出结果为:
[PosixPath(‘2.txt‘), PosixPath(‘1.txt‘)]
2.txt
This|tutorial|introduces|the|reader|informally|to|the|basic|concepts|and|features|of|the|Python|language|and|system|It|helps|to|have|a|Python|interpreter|handy|for|hands|on|experience|but|all|examples|are|self|contained|so|the|tutorial|can|be|read|off|line|as|well|
1.txt
Python|is|an|easy|to|learn|powerful|programming|language|It|has|efficient|high|level|data|structures|and|a|simple|but|effective|approach|to|object|oriented|programming|Python|s|elegant|syntax|and|dynamic|typing|together|with|its|interpreted|nature|make|it|an|ideal|language|for|scripting|and|rapid|application|development|in|many|areas|on|most|platforms|
标签:rom ica The example orm xpath rod reader read
原文地址:http://blog.51cto.com/13959448/2319550