我正在编写一个程序来通过python发送电子邮件。我有不同的定义,其中包含包含电子邮件用户名和电子邮件密码等的变量。然后我有另一个定义,实际发送电子邮件,但它需要包含电子邮件用户名和密码等的变量。如何调用来自不同def的变量?对不起,措辞怪异。我不知道该怎么说:P谢谢!
def get_email_address():
#the code to open up a window that gets the email address
Email = input
def get_email_username():
#the code to open up a window that gets email username
Email_Username = input
#same for the email recipient and email password
def send_email():
#here I need to pull all the variables from the other def's
#code to send email
您将需要在辅助函数中返回值并从主send_email()
函数中调用这些函数,并将返回的值分配给变量。像这样:
def get_email_address():
#the code to open up a window that gets the email address
Email = input
return Email
def get_email_username():
#the code to open up a window that gets email username
Email_Username = input
return Email_Username
#same for the email recipient and email password
def send_email():
# variables from the other def's
email_address = get_email_address()
email_username = get_email_username()
#code to send email
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句