私はPythonを使ってファイルを読み込もうとしています。 この私のファイルtest.txtの:Pythonではどのようにline.rstrip()を使用しますか?
Hello World
My name is Will
What's your name?
これは私のpythonのコードです:
fhand = open('test.txt')
for line in fhand:
line.rstrip()
print line
私はline.rstrip()
を使用するかどうかに関係なく、出力は次のように常にある:
Hello World
My name is Will
What's your name?
このようにrstrip()
を使用して空行なしで出力するにはどうすればよいですか?
Hello World
My name is Will
What's your name?