我正在抓取一些数据,数据以两个段落的形式出现在我身上,然后存储在一个分为两行的变量中。我想存储没有换行符的数据,看起来像一个段落。
我尝试了strip
和join
函数,但对我不起作用。
# Assume that these are the two paragraphs
str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
mystr=" ".join(str.split())
print(mystr)
应打印
Lorem Ipsum is simply dummy text of the printing and typesetting Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
答案 0 :(得分:0)
我想这就是你想要的...
string = """
"Lorem Ipsum is simply dummy text of the printing and typesetting industry"
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
"""
mystr= str.replace('"','')
mystr = mystr.replace('\n','. ')
print (mystr)
此代码从字符串中删除引号,然后将换行符更改为句点和空格,因此输出为
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s