名称错误:未定义名称“xxxx”

2024-05-03 15:17:44 发布

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

当我在两个级别的函数中调用函数时,会出现以下错误:“名称错误:未定义名称‘destinateries’”:

即使我在函数中将其声明为全局变量,也会出现错误:

def PostToFaceBookWall(msg):
    global destinataires
    try:
    ....
    except Exception as e:
        subject = 'xxxxxxxxxxx'
        error  = str(e)
        SendMail(destinataires,subject,error)

def get_prices_for_next_days():
    ....
    subject = "xxxxx")
    html = "xxxxxx"
    SendMail(destinataires,subject,html) # NO PROBLEM WITH THIS INSTRUCTION : I GET MAIL
    PostToFaceBookWall(Msg2FB) # PROBLEM WITH THIS INSTRUCTION : I GET ERROR 
         
    
def SendMail(dest,sujet, msg):
    """Send a mail"""
    
if __name__ == '__main__':
    destinataires = ['xxxxx@xxxx.xxx'] #a global variable
    get_prices_for_next_days()

级别包含功能是否有限? 函数中定义的全局变量在调用的子函数中是未知的


Tags: 函数名称getdef错误msgerror级别