question = "question:"
# QUESTION
f = open('dopeit.rtf', encoding="utf8", errors='ignore')
line = f.readline()
while line:
if question in line:
newline = line.replace('Question: ', '"')
print(newline + '"', end=",")
# use realine() to read next line
line = f.readline()
f.close()
输出是这样的
","Who directed Star Wars?
","Who was the only non Jedi in the original Star Wars trilogy to use a lightsaber?
","What kind of flower was enchanted and dying in Beauty and the Beast?
","Which is the longest movie ever made?
我希望它是这样的:
"Who directed Star Wars?","Who was the only non Jedi in the original Star Wars trilogy to use a lightsaber?","What kind of flower was enchanted and dying in Beauty and the Beast?","Which is the longest movie ever made?
那么我怎样才能做出这些改变呢?我尝试使用“end”命令,但它似乎仍能将其带到下一行?我做错什么了吗
相关问题 更多 >
编程相关推荐