简体   繁体   English

列表对象没有属性拆分

[英]List Object has no Attribute Split

Basically what the title says: I am trying to create a program that detects Usernames and Passwords in a file.基本上是标题所说的:我正在尝试创建一个程序来检测文件中的用户名和密码。 However, whenever I run it, it comes up with this error:但是,每当我运行它时,都会出现此错误:

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'

Here is the code where it is going wrong:这是出错的代码:

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

This is what is inside of the .txt file:这是 .txt 文件中的内容:

TheCloudMiner,Password123
TestUser,TestPass
Testing,Tester
Username,Password

I have read through some of the other answers but they are no help to me.我已经阅读了其他一些答案,但它们对我没有帮助。 Any help would be much appreciated.任何帮助将非常感激。

readlines() returns a list of strings, not a string. readlines()返回一个字符串列表,而不是一个字符串。 You want to apply split() on each line separately, so you should iterate over it with something like你想分别在每一行上应用split() ,所以你应该用类似的东西迭代它

for line in open(...).readlines():
    username, password = line.split(",")
    # rest of your code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM