我正在尝试将列表分成两个空格。
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
高级套餐包含:
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)
premium_users.txt文件包含高级版本用户及其ID,如下所示:
m1 7868686865487
m2 5647893783364
m3 8493389279895
m4 8546583469246
依此类推。premium_test.py
import premium_users as pu
pu.premium_users_writer('premium_user.txt')
s4 = pu.premium_users_checker('premium_user.txt')
print(s4)
追踪:
Traceback (most recent call last):
File "F:/PyCharm Python Works/OpenCity/premium/tester.py", line 3, in <module>
p1, p2 = rc.users_reader('premium_users.txt')
File "F:\PyCharm Python Works\OpenCity\reusable_code.py", line 34, in users_reader
p10, p11 = p2[int(i)].rstrip('\n').split(' ')
ValueError: not enough values to unpack (expected 2, got 1)
[我正在尝试读取文件,并检查用户ID或用户名是否包含高级版本。谢谢。