[Python] Wrap Two Array into another variable [duplicate]

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I had coded a function called readfile has two array list but i cannot return two array. Therefore, I need to wrap it inside object variable and return it. Below is my code:

    def __init__(self, environment):
    super().__init__(environment)
    self.loginUsername = []
    self.loginPassword = []
    self.loginInfo = None

    def on_start(self):
    self.readfile()

    def readfile(self):
    try:
    with open("users.txt", "r") as loginFile:
    for line in loginFile:
    username, password = line.strip().split(',')
    self.loginUsername.append(username)
    self.loginPassword.append(password)

    except FileNotFoundError:
    print("The file user.txt does not exist.")
    except Exception as e:
    print(f"An error occurred: {e}")

    return self.loginInfo


    Please help. Thanks in advance.

    Continue reading...

Compartilhe esta Página