当我运行下面的代码时,没有得到预期的输出。请纠正我。
import socket
import re
NodeName=socket.gethostname()
change_hostname_list=['/etc/hosts1','/etc/sysconfig/network1']
for file in change_hostname_list:
infile=open(file,'r').read()
print NodeName
print file
if re.search('NodeName',file):
print "DOOO"
我需要输出"DOOO"
���我得到的结果如下:
root@test06> python test.py
test06
/etc/hosts1
test06
/etc/sysconfig/network1
root@test06>
re.search(file, NodeName)
? - Nebril