with open('/etc/mcelog/mcelog.conf', 'r+') as fp:
for line in fp:
if re.search("no-syslog =", line) and re.search("= no", line):
memoryErrors = readLogFile("/var/log/messages")
mcelogPathFound = true
break
elif re.search("no-syslog =", line) and re.search("= yes", line):
continue
elif re.search("logfile =", line):
emoryErrors = readLogFile(line.split("=")[1].strip()) # Here I want to pass the value "/tmp/logfile" but currently "logfile = /tmp/logfile" is getting passed
mcelogPathFound = true
break
fp.close()
我喜欢
configparser
模块的建议,下面是一个例子(python3)对于给定的输入,它将输出
reading /var/log/messages
将代码更改为:
这是因为你只想读这行的一部分,而不是整个内容,所以我就用“=”号把它分开,然后去掉空白
只需拆分行即可获得所需的值:
但是,您可能需要查看configparser module的文档。在
相关问题 更多 >
编程相关推荐