这是代码:
import os
import re
import subprocess
current_setting = list()
with open('/etc/init/control-alt-delete.conf' ,'r')as fp:
for line in fp:
if not line.startswith('#'):
current_setting.append(line.strip())
current_setting.remove('')
print current_setting
desired_setting = list()
with open('ctl_alt_del', 'r') as f:
for line in f:
desired_setting.append(line.strip())
print desired_setting
if set(current_setting) == set(desired_setting):
print 'The file has to be modified'
我得到的输出为:
['start on control-alt-delete', '', 'exec /sbin/shutdown -r now "Control-Alt-Delete pressed"']
['start on control-alt-delete', 'exec /sbin/shutdown -r now "Control-Alt-Delete pressed"']
除了第一个列表的两个条目之间的空白之外,这两个列表是相同的。因此,比较给出了错误的值。如何删除那个空白?请帮忙。先感谢您。