简体   繁体   中英

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:

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. You want to apply split() on each line separately, so you should iterate over it with something like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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