Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 电子邮件函数列表索引必须是整数或切片,而不是函数_Python 3.x_List_Email - Fatal编程技术网

Python 3.x 电子邮件函数列表索引必须是整数或切片,而不是函数

Python 3.x 电子邮件函数列表索引必须是整数或切片,而不是函数,python-3.x,list,email,Python 3.x,List,Email,大家好, 以上是我的代码,我正在努力理解是什么导致了我的问题。当我运行代码时,它会说“列表索引必须是整数或切片,而不是函数”,我试图让助手根据所说的名称在哪里选择收件人做出响应 ,,, def sendEmail(reciever, subject, content): server = smtplib.SMTP('smtp.gmail.com', 587) senderemail = 'Test3@gmail.com' epwd = 'P

大家好,

以上是我的代码,我正在努力理解是什么导致了我的问题。当我运行代码时,它会说“列表索引必须是整数或切片,而不是函数”,我试图让助手根据所说的名称在哪里选择收件人做出响应

,,, 
   def sendEmail(reciever, subject, content):
        server = smtplib.SMTP('smtp.gmail.com', 587)
        senderemail = 'Test3@gmail.com'
        epwd = 'Password'
        server.starttls()
        server.login(senderemail, epwd)
        email = EmailMessage()
        email['from'] = senderemail
        email['To'] = reciever
        email['Subject'] = subject
        email.set_content(content)
        server.send_message(email)
        server.close
    if __name__ == "__main__":
        wishme()
        while True:
            query = takeCommandMIC().lower()
            if 'time' in query:
                time()
            elif 'date' in query:
                date()
            elif 'email' in query:
                  email_list = {
            'John': 'test@gmail.com'
            'Alan': 'Test2@gmail.com'
            'Fraser' : 'test3@gmail.com'
        }
                try:
                    speak ('To whom should I send an Email?')
                    name = takeCommandMIC
                    reciever = email_list[name]
                    speak("What is the Subject of the Email?")
                    subject = takeCommandMIC
                    speak('What should I say?')
                    content = takeCommandMIC()
                    sendEmail(reciever, subject, content)
                    speak("Email has been sent")
                except Exception as e:
                    print(e)
                    speak("Unable to send the Email")
            elif 'offline' in query:
                quit()
,,,

那很容易。无法在词典列表中查找名称。尝试:

Trace:


PS C:\Users\rober> & C:/Users/rober/AppData/Local/Programs/Python/Python39/python.exe c:/Users/rober/Documents/Python/JARVIS.py
  File "c:\Users\rober\Documents\Python\JARVIS.py", line 115
    'Alan': 'Test2@gmail.com'
          ^
SyntaxError: invalid syntax
PS C:\Users\rober> 

没有明显的原因可以解释为什么要将每个接收器作为自己的字典存储在列表中。

欢迎使用SO!请提供-您的代码目前无法运行。还有,这个问题的堆栈跟踪是什么?嗨,Sophoros,我已经用MREW更新了堆栈跟踪呢?很抱歉,我错过了,我如何打印堆栈跟踪我以前从来没有这样做过谢谢链接,解释得很好!谢谢,我试过了,并且:使它期望一个表达式,并要求它们用分号分隔
email_list = {
   'John': 'test@gmail.com'
   'Alan' : 'Test2@gmail.com'
   'Fraser' : 'test3@gmail.com'
}