![](/img/trans.png)
[英]search a word in a file and print the line number where that word occurs in python
[英]Search and print word in line in python
我想在文本文件中搜索第二列,如果它與特定單詞匹配,則不想打印該行:
Title = line.split(" ")
TitleCheck =["apple" , "banana" , "mango"]
if not Title[1].startsWith(for word in TitleCheck)
print Title[1]
但它給出了錯誤
SyntaxError: invalid syntax
是的。 這是無效的語法。
嘗試:
if not Title[1].startswith(tuple(TitleCheck))
檢查startswith 的拼寫。 駝峰式不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.