mercredi 8 janvier 2020

ValueError: not enough values to unpack (expected 2, got 1) 'xxx':'xxx'

I am trying to spilt the list into two with a space. reusable_code.py

def user_writer(x, h, k, j):
    import random as ran
    import file.file as f
    input_file = x
    p2 = int(input("How many members do you want to add to " + h + " to database? "))
    if p2 == 0:
        print('No number is given. So, exiting the function.\n')
        return 0
    p1 = []
    p3 = []
    for i in range(p2):
        member = input("Type the person's name. ")
        p1.append(member)
        id1 = ran.randint(k, j)
        p3.append(str(id1))
    for i, e in zip(p1, p3):
        ui = (i + ' ' + e + '\n')
        f.file_append(input_file, ui)
    print()
    if not p2 == 0:
        print("Done")


def users_reader(x):
    import file.file as f
    input_file = x
    user1r = f.file_read(input_file)
    p2 = []
    p4 = []
    p5 = []
    for data in user1r:
        p2.append(data)
    for i in range(len(p2)):
        p10, p11 = p2[int(i)].rstrip('\n').split(' ')
        p4.append(p10), p5.append(p11)
    return p4, p5


def users_checker(n, y):
    p1, p2 = users_reader(y)
    y = int(input("Choose between the below options." + '\n' + '1.Username' + '\n' + '2.ID' + '\n' +
                  "Which one would you like to enter? "))
    x = ""
    if y == 1:
        x = input("Enter the username to check whether you have " + n + " or not: ")
    elif y == 2:
        x = input("Enter the id to check whether you have " + n + " or not: ")
    elif not 0 > y > 3:
        print("Please enter the correct number!")
    if x.isnumeric():
        k = 0
        for _ in p2:
            if x in p2:
                if x == p2[k]:
                    z = p1[int(k)]
                    return "The id " + x + " has a " + n + " version. The username of " + x + " is " + z + "."
            else:
                return "Can't able to find id in the database, please check the id or name!"
            k += 1
    else:
        k = 0
        for _ in p2:
            uo = x.capitalize()
            ui = uo in p1[int(k)]
            if ui:
                uo = p1[int(k)]
                if uo in p1:
                    if ui:
                        z = p2[int(k)]
                        return "The username " + uo + " has a " + n + " version. The id of " + uo + " is " + z + "."
                else:
                    return "Can't able to find the username in the database, please check the id or name!"
            else:
                return "Please enter a valid name!"
            k += 1

I have given the full code. The premium package contains premium_users.py

def premium_users_writer(x):
    import reusable_code as rc
    rc.user_writer(x, 'premium_users.txt', 100000000, 99999999999)


def premium_users_reader(x):
    import reusable_code as rc
    return rc.users_reader(x)


def premium_users_checker(x):
    import reusable_code as rc
    return rc.users_checker('premium', x)

The file contains premium version users and their id like this,

m1 7868686865487
m2 5647893783364
m3 8493389279895
m4 8546583469246

and so on. And I am trying to read the file and check whether user id or username contains premium version. Thank you.

Aucun commentaire:

Enregistrer un commentaire