我在家中運行自己的業務,並在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