我有下一个代码,该代码从多个文件中读取,解析获得的行并打印结果:
import os
import re
files=[]
pars=[]
for i in os.listdir('path_to_dir_with_files'):
files.append(i)
for f in files:
with open('path_to_dir_with_files'+str(f), 'r') as a:
pars.append(re.sub('someword=|\,.*|\#.*','',a.read()))
for k in pars:
print k
Run Code Online (Sandbox Code Playgroud)
但我有在输出多个新线路的问题:
test1
test2
Run Code Online (Sandbox Code Playgroud)
取而代之的是,我想获得下一个结果,在输出中没有空行:
test1
test2
Run Code Online (Sandbox Code Playgroud)
等等。
我尝试过使用regexp:
pars.append(re.sub('someword=|\,.*|\#.*|^\n$','',a.read()))
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。我也尝试使用strip()和rstrip()包括replace。它也不起作用。
能否请你帮忙?
对于愚蠢的问题我很抱歉,但是请告诉我:KVM可以在没有libvirt的情况下工作吗?
根据我糟糕的经历,我看到了基于libvirt的KVM功能.
感谢您的回复.
我有包含yaml文件的下一个目录路径:
test/1.yaml
test/dev.yaml
test/dev0_r.yaml
Run Code Online (Sandbox Code Playgroud)
等等
如何匹配完全在test /目录中但不在子目录(如test / test1 / dev.yaml)中的所有Yaml文件
我正在尝试使用globing:
test/*.yaml
Run Code Online (Sandbox Code Playgroud)
但在https://regex101.com/上不起作用
我该如何实现?
regex ×2
file ×1
kvm ×1
libvirt ×1
linux ×1
linux-kernel ×1
python ×1
regex-greedy ×1
regex-group ×1
string ×1