我有一個文本文件。如何打印文本文件的行如果分號在末尾
Test.txt的
this is line one; this line one
this is line two;
this is line three
我想打印含有分號線,但分號應該是行的末尾。
我的代碼
search = open("Test.txt","r")
for line in search :
if ";" in line:
semi = line.split(";")
if semi[-1] == "\n":
print(line)
輸出
this is line two;
我的代碼工作正常,但我希望有一個更好的方式來做到這一點。 任何人都可以告訴我簡短和最pythonic的方式來做到這一點?
將這項工作在Python 2.7? – sam
@sam是的,我測試過了。 –
謝謝....現在這段代碼工作正常,我認爲這是最短的做法 – sam