我正在编写一个程序来通过python发送电子邮件.我有不同的def,它包含包含电子邮件用户名和电子邮件密码等的变量.然后我有另一个def实际发送电子邮件,但它需要包含电子邮件用户名和密码等的变量.我怎么能调用来自不同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
Run Code Online (Sandbox Code Playgroud)
Hol*_*rel 10
您需要在辅助函数中返回值,并从main 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44551 次 |
| 最近记录: |