我正在将值从文本文件读入字符串。当所有的值被读入字符串时,我需要把它们放进引号中,并用逗号隔开
这方面的一个例子是在我的文本文件中:
123456789
123456789
123456789
123456789
我把它读入我的字符串data_to_read
,我想让它显示:
data_to_read = "1234567892","1234567892","1234567892","1234567892"
我可以把它读入字符串,但不知道如何加引号和逗号
with open('C:\uiautomation\Test_Files\Securities_to_Delete.txt', 'r') as input:
data_to_read = "".join(input.readlines()[1:])
print data_to_read
这将输出:
'123456789\n123456789\n123456789\n123456789'
您可以使用
replace
string方法执行以下操作:这也适用于支持f字符串的python版本:
相关问题 更多 >
编程相关推荐