亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有唯一字符的 Python 字符串?無效的語法

具有唯一字符的 Python 字符串?無效的語法

慕碼人8056858 2023-03-08 14:39:57
我讓用戶輸入他們的電子郵件地址。但是,我假設 Python 無法識別特殊字符“@”,但我不確定重新編碼/讓用戶輸入如何將該特殊字符識別為字符串的一部分。import smtplibsender_email = "[email protected]"rec_email = input('Enter a email to send to: ')password = "Password"SUBJECT = "Subject Line Test"TEXT = "Test Text"message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)server = smtplib.SMTP('smtp.gmail.com', 587)server.starttls()server.login(sender_email, password)print("Login success")server.sendmail(sender_email, rec_email, message)print("Email has been ent to ", rec_email)server.quit()我該如何糾正這個問題?#Error: using [email protected] as my inputTraceback (most recent call last):  File "testss.gyp", line 4, in <module>    rec_email = input('Enter a email to send to: ')  File "<string>", line 1    [email protected]                    ^SyntaxError: invalid syntax
查看完整描述

1 回答

?
慕后森

TA貢獻1802條經驗 獲得超5個贊

我懷疑您使用的是 Python 2。在 Python 2 中,嘗試在輸入字符串上input()運行。eval()電子郵件地址不是有效的 python,因此您會收到語法錯誤。嘗試改用raw_input()。



查看完整回答
反對 回復 2023-03-08
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號