MIMEText 和 sqlite 中的语法错误
SyntaxError in MIMEText and sqlite
此代码发送有关新文章的通知,该文章存储在我的程序之前指定的数据库中(这是 RSS 供稿器的元素)。
def send_notification(article_title, article_url):
smtp_server=smtplib.SMTP('smtp.gmail.com', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.login('your_email@gmail.com','password')
msg = MIMEText(f'\nHi, this is new article: {article_title}. \nYou can read this in {article_url}')
msg['Subject']='New article is available'
msg['From']='your_email@gmail.com'
msg['To']='destination_email@gmail.com'
smtp_server.send_message(msg)
smtp_server.quit()
我收到一条消息 "SyntaxError: invalid syntax" 行:
msg = MIMEText(f'\nHi, this is new article: {article_title}. \nYou can read this in {article_url}')
我认为是{}括号引起的。
谁能帮我修好它?
PS 我在 Python3 工作。
这应该可以解决您的语法问题:
msg = MIMEText('\nHi, this is new article: {}. \nYou can read this in {}'.format(article_title, article_url))
阅读 python here
中有关字符串格式的更多信息
此代码发送有关新文章的通知,该文章存储在我的程序之前指定的数据库中(这是 RSS 供稿器的元素)。
def send_notification(article_title, article_url):
smtp_server=smtplib.SMTP('smtp.gmail.com', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.login('your_email@gmail.com','password')
msg = MIMEText(f'\nHi, this is new article: {article_title}. \nYou can read this in {article_url}')
msg['Subject']='New article is available'
msg['From']='your_email@gmail.com'
msg['To']='destination_email@gmail.com'
smtp_server.send_message(msg)
smtp_server.quit()
我收到一条消息 "SyntaxError: invalid syntax" 行:
msg = MIMEText(f'\nHi, this is new article: {article_title}. \nYou can read this in {article_url}')
我认为是{}括号引起的。 谁能帮我修好它?
PS 我在 Python3 工作。
这应该可以解决您的语法问题:
msg = MIMEText('\nHi, this is new article: {}. \nYou can read this in {}'.format(article_title, article_url))
阅读 python here
中有关字符串格式的更多信息