如何将输入从一个文件导入另一个文件并进行同步?

时间:2019-05-15 15:23:20

标签: python file-io

我想将我在一个文件中的输入与另一个文件中的变量同步。我应该在哪里将return语句放在登录函数中,以便将变量导入另一个文件并在那里进行同步?

我试图将返回的用户名,密码放入登录函数中,并将该登录函数导入其他文件中并获取变量

class main:
    def __init__(self, master):
        # Window
        self.master = master
        # Some Usefull variables
        self.username = StringVar()
        self.password = StringVar()
        self.n_username = StringVar()
        self.n_password = StringVar()
        # Create Widgets
        self.widgets()

    # Login Function
    def login(self):
        # Establish Connection
        with sqlite3.connect('quitq.db') as db:
            c = db.cursor()

        return self.username, self.password  ### this one I added to try to send other file

        # Find user If there is any take proper action
        find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
        c.execute(find_user, [(self.username.get()), (self.password.get())])
        result = c.fetchall()
        if result:
            self.logf.pack_forget()
            self.head['text'] = self.username.get() + '\n Loged In'
            self.head['pady'] = 150
            top1.deiconify()

        else:
            ms.showerror('Oops!', 'Username Not Found.')

这是我尝试使用return语句以便在以下代码中使用的主文件:

import datetime
import email
import imaplib
import menu

username, password = menu.main.login()

a = username
b = password

EMAIL_ACCOUNT = a
PASSWORD = b

我收到此错误:

Traceback (most recent call last):
  File "C:code/menu.py", line 4, in <module>
    import email_client
  File "C:\code\email_client.py", line 4, in <module>
    import menu
  File "C:\code\menu.py", line 285, in <module>
    email_from, email_to, local_message_date, subject, body = email_client.get_email()
AttributeError: module 'email_client' has no attribute 'get_email'

0 个答案:

没有答案