在Python3.2中生成具有特定文本文件数据的列
这意味着要求用户输入用户名,在文本文件中找到用户名,然后在列中输出,只输出他们的信息。信息包括ID、姓氏、加入年份、状态、预订的住宿和积分。我该怎么做在Python3.2中生成具有特定文本文件数据的列,python,Python,这意味着要求用户输入用户名,在文本文件中找到用户名,然后在列中输出,只输出他们的信息。信息包括ID、姓氏、加入年份、状态、预订的住宿和积分。我该怎么做 import time membr = int(input("Do you have a membership already?\n" "1.Yes\n" "2.No\n" "Option: ")) if membr == 1:
import time
membr = int(input("Do you have a membership already?\n"
"1.Yes\n"
"2.No\n"
"Option: "))
if membr == 1:
MemberID = []
LastName = []
YearJoined = []
Status = []
NightsBooked = []
Points = []
theirid = input("Please enter your id number (It is case sensitive): ")
Myfile = open("Memberships.txt", "r")
x = 0
for line in Myfile:
if theirid in line: return(line)
information = line.split(",")
MemberID.append(information[0])
LastName.append(information[1])
YearJoined.append(information[2])
Status.append(information[3])
NightsBooked.append(information[4])
Points.append(information[5])
x = x+1
Myfile.close()
print("{0:<18} {1:<18} {2:<18} {3:<18} {4:<18} {5:<18}".format("MemberID", "LastName", "YearJoined", "Status", "NightsBooked", "Points"))
for y in range(1,x):
print("{0:<18} {1:<18} {2:<18} {3:<18} {4:<18} {5:<18}".format(MemberID[y],LastName[y],YearJoined[y],Status[y],NightsBooked[y],Points[y]))
time.sleep(2)
mainmenu()
elif membr == 2:
createnewuser()
else:
print("Invalid")
time.sleep(2)
mainmenu()
导入时间
membr=int(输入(“您已经有会员资格了吗?\n”
“1.是\n”
“2.否\n”
“选项:”)
如果membr==1:
MemberID=[]
LastName=[]
年加入=[]
状态=[]
NightsBooked=[]
点数=[]
theirid=input(“请输入您的id号(区分大小写):”)
Myfile=open(“Memberships.txt”、“r”)
x=0
对于Myfile中的行:
如果ID在行中:返回(行)
信息=行。拆分(“,”)
MemberID.append(信息[0])
LastName.append(信息[1])
YearJoined.append(信息[2])
状态.追加(信息[3])
NightsBooked.append(信息[4])
点。追加(信息[5])
x=x+1
Myfile.close()
print(“{0:您不需要在那里返回该行
...
YearJoined = []
Status = []
NightsBooked = []
Points = []
theirid = input("Please enter your id number (It is case sensitive): ")
Myfile = open("Memberships.txt", "r")
x = 0
for line in Myfile:
# this will use the line found to do your work.
if theirid in line:
information = line.split(",")
MemberID.append(information[0])
LastName.append(information[1])
YearJoined.append(information[2])
Status.append(information[3])
NightsBooked.append(information[4])
Points.append(information[5])
x = x+1
Myfile.close()
print("{0:<18} {1:<18} {2:<18} {3:<18} {4:<18} {5:<18}".format("MemberID", "LastName", "YearJoined", "Status", "NightsBooked", "Points"))
for y in range(1,x):
print("{0:<18} {1:<18} {2:<18} {3:<18} {4:<18} {5:<18}".format(MemberID[y],LastName[y],YearJoined[y],Status[y],NightsBooked[y],Points[y]))
time.sleep(2)
mainmenu()
elif membr == 2:
createnewuser()
else:
print("Invalid")
time.sleep(2)
mainmenu()
。。。
年加入=[]
状态=[]
NightsBooked=[]
点数=[]
theirid=input(“请输入您的id号(区分大小写):”)
Myfile=open(“Memberships.txt”、“r”)
x=0
对于Myfile中的行:
#这将使用找到的行来完成您的工作。
如果他们的意见一致:
信息=行。拆分(“,”)
MemberID.append(信息[0])
LastName.append(信息[1])
YearJoined.append(信息[2])
状态.追加(信息[3])
NightsBooked.append(信息[4])
点。追加(信息[5])
x=x+1
Myfile.close()
打印({0:为什么要使用返回(行)
?我不知道我在做实验。也许你能帮上忙