在从原始输入接收的输入中保留换行符

2024-05-16 08:21:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个脚本,允许我从命令行发送电子邮件。脚本工作正常;但是,我希望能够在电子邮件正文中添加换行符('\n')。原始输入函数将'\n'作为文字输入。我该怎么办?你知道吗

示例:

body = raw_input('Enter your message: ')

>>>Enter your message: This\nShould\nbe\non\n6\nlines
>>>print(body)
'This\nShould\nbe\non\n6\nlines'

我想展示一下:

>>>Enter your message: This\nShould\nbe\non\n6\nlines
>>>print(body)
'This
Should
be
on
6
lines'

Tags: 函数命令行脚本messageyour电子邮件bodythis