如何删除文本的段落?
我成功地创建了一个发送多个电子邮件的程序,但是我没有成功地正确格式化文本。
每当我尝试创建新行时,Python都会自动插入一个新段落,而我不想要。我试图将.lstrip放在文本块的ENT之后,但在“”但没有起作用之后。
文本应该是这样的:
"Dear owner,
Our records indicate that your payment have not been received so far.
The total due is:"
但是在电子邮件中打印出来:
"Dear owner
Our records indicate that your payment have not been received so far.
The total due is:"
请参阅下面的代码,谢谢对于任何输入。
import email
import win32com.client as client
import pandas as pd
tabela = pd.read_excel('over60.xlsx')
#print(tabela)
data = tabela[['Customer','Email','Owner','Total Due']].values.tolist()
for dado in data:
owner_number = dado[0]
to = dado[1]
owner = dado[2]
amount = dado[3]
outlook = client.Dispatch('Outlook.Application')
account = outlook.session.Accounts['myemail.com']
email = outlook.CreateItem(0)
email.To = 'myemail.com'
email.Subject = f'Past Due Notice - {owner} - {owner_number}'
email.Body =f""" Dear {owner},
Our records indicate that your payment have not been received so far.
The total due is ${amount: .2f}.
I have succesfully created a program that send multiple emails, but I'm not having success to format the text correctly.
Every time that I try to create a new line, python automatically inserts a new paragraph and I don't want that. I have tried to place .lstrip at the ent of the text block, after the """ but didn't work.
The text should be like this:
"Dear owner,
Our records indicate that your payment have not been received so far.
The total due is:"
But is being printed on the email like this:
"Dear owner
Our records indicate that your payment have not been received so far.
The total due is:"
Please see my code below, thanks for any inputs.
import email
import win32com.client as client
import pandas as pd
tabela = pd.read_excel('over60.xlsx')
#print(tabela)
data = tabela[['Customer','Email','Owner','Total Due']].values.tolist()
for dado in data:
owner_number = dado[0]
to = dado[1]
owner = dado[2]
amount = dado[3]
outlook = client.Dispatch('Outlook.Application')
account = outlook.session.Accounts['myemail.com']
email = outlook.CreateItem(0)
email.To = 'myemail.com'
email.Subject = f'Past Due Notice - {owner} - {owner_number}'
email.Body =f""" Dear {owner},
Our records indicate that your payment have not been received so far.
The total due is ${amount: .2f}.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
多行字符串包括在行开始时的缩进,请尝试在屏幕左侧的线路开始,或用
\ n
eg替换新线n 呈现为新线,而不是字面字符“ \ n”
The multiline string is including the indent at the start of the line, try unindenting the start of the line all the way to the left of the screen, or replacing newlines with
\n
e.g:\n
renders as a newline and not the literal characters "\n"使用
“”“”
保留Whitespace,因此像这样的字符串实际上将这些领先的空间放入。
如果您想继续使用多行字符串,则可以应用
ixplast.spection.cleandoc
这...
Using
"""
preserves whitespace so a string like this...Actually puts those leading spaces in.
If you want to keep using a multi-line string, you can apply something like
inspect.cleandoc
to clean up the string, like this...您可以写出多行字符串,例如:(
像元组一样,但没有逗号),
并且它可以打印
您可以正确保留代码标识
You can write your multiline string like:
(like a tuple but without commas)
and it prints
moreover you can keep your code identation correctly