我有一个文本文件。如何打印文本文件的行如果分号在末尾
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