在Python中从一个函数调用变量到另一个函数
发布于 2021-01-29 17:14:35
我正在编写一个程序来通过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
关注者
0
被浏览
103
1 个回答
-
您将需要在辅助函数中返回值并从主
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
推荐阅读
-
在Java中,如何从一个构造函数调用另一个构造函数?
2022-02-17 关注 0 浏览174 1答案
-
从另一个函数调用在一个函数内部定义的变量
2021-01-29 关注 0 浏览161 1答案
-
如何通过ng-click从另一个函数调用一个函数?
2021-02-01 关注 0 浏览149 1答案
-
在第一个ajax函数调用完全完成之后,jQuery继续另一个ajax函数
2021-01-31 关注 0 浏览74 1答案
-
如何从一个cfc文件中的函数查询中调用另一个CFC文件中的函数?
2021-06-04 关注 0 浏览111 1答案
-
如何从GCP中的另一个Go Cloud函数调用Go Cloud函数
2021-02-01 关注 0 浏览89 1答案
-
在Swift中将列表从一个函数传递到另一个函数
2021-01-31 关注 0 浏览89 1答案
-
在Python中的另一个函数中获取调用者函数名称?
2021-01-29 关注 0 浏览178 1答案
-
调用另一个函数中定义的函数
2021-01-29 关注 0 浏览95 1答案
-
Python模拟补丁另一个函数中的一个函数
2021-01-29 关注 0 浏览73 1答案