开发者

Reading file in python without linebreak

开发者 https://www.devze.com 2023-04-07 00:49 出处:网络
I want to be able to read a file and add a string onto it line by line without having a line break in the middle.

I want to be able to read a file and add a string onto it line by line without having a line break in the middle.

text_file = open("read_it.txt", "r")
print text_file.readline() + "0123456789"

Outputs to

>>
text
0123456789
>>

I would like have it output to this format

开发者_运维技巧>>
text0123456789
>>


Use the rstrip method:

text_file.readline().rstrip() + "0123456789"
0

精彩评论

暂无评论...
验证码 换一张
取 消