[英]List Object has no Attribute Split
基本上是标题所说的:我正在尝试创建一个程序来检测文件中的用户名和密码。 但是,每当我运行它时,都会出现此错误:
Traceback (most recent call last):
File "C:/Users/tom11/Desktop/Data Login.py", line 33, in <module>
content = raw.split(",")
AttributeError: 'list' object has no attribute 'split'
这是出错的代码:
UCheck = ""
PCheck = ""
Username = input("Username: ")
Attempts = 3
while UCheck != "Y":
lines = True
f = open('Data.txt', 'r+')
while lines:
raw = f.readlines()
content = raw.split(",")
if len(raw) == 0:
print("That Username does not exist!")
Username = input("Username: ")
elif Username == content[0]:
UCheck == "Y"
lines = False
这是 .txt 文件中的内容:
TheCloudMiner,Password123
TestUser,TestPass
Testing,Tester
Username,Password
我已经阅读了其他一些答案,但它们对我没有帮助。 任何帮助将非常感激。
readlines()
返回一个字符串列表,而不是一个字符串。 你想分别在每一行上应用split()
,所以你应该用类似的东西迭代它
for line in open(...).readlines():
username, password = line.split(",")
# rest of your code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.