我在家中运行自己的业务,并在2天前开始使用Python。我正在尝试编写一个脚本,它将逐行搜索我的日志文件,并告诉我系统是否与我的强制性命名方案不匹配。有多种不同的方案,我希望脚本能够找到它们。我尝试使用列表(如下所示),但不会工作,然后我用正常的括号尝试,并给了我一个错误(需要左操作数,而不是元组)。我注意到给我一个问题的线条。Python 2.7.2一个变量的多个值
#variables
tag = ["DATA-", "MARK", "MOM", "WORK-"] #THIS ONE!!!!!!
#User Input
print "Please select Day of the week"
print "1. Monday"
print "2. Tuesday"
print "3. Wednesday"
print "4. Thursday"
print "5. Friday"
print "6. Saturday"
print "7. Sunday"
day = input("> ")
#open appropriate file and check to see if 'tag' is present in each line
#then, if it doesn't, print the line out.
if day == 1:
f = open('F:\DhcpSrvLog-Mon.log', 'r')
for line in f:
if tag in line: #THIS ONE!!!!!!!!!!!!!
pass
else:
print line
任何提示或技巧将不胜感激!
这样做!非常感谢! – user1197368 2012-02-08 15:00:29