小编mic*_*cma的帖子

在Python中调用一个函数的变量到另一个函数

我正在编写一个程序来通过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)

python

9
推荐指数
1
解决办法
4万
查看次数

缺少1个必要的位置参数:'self'

这是我的代码:

class Email_Stuff():
    def __init__(self):
        self.emailaddr = None
        self.recipaddr = None
        self.EmailUser = None
        self.EmailPass = None
    def From_Email(self):
        self.emailaddr = turtle.textinput("Your Email", "What is your email address?")
    def To_Email(self):
        self.recipaddr = turtle.textinput("Client Email", "What is your client's email address?")
    def Email_Username(self):
        self.EmailUser = turtle.textinput("Your Email Username", "What is your email username?")
    def Email_Password(self):
        self.EmailPass = turtle.textinput("Your Email Password", "What is your email Password?")
    def Send_Email(self):
        print (self.emailaddr) #these are here for me to see if it is the right …
Run Code Online (Sandbox Code Playgroud)

python

4
推荐指数
1
解决办法
6万
查看次数

标签 统计

python ×2