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