I cant seem to write each line in a file so Its like a one long string like : "a,1;b,2;c,3". I want to write a method that deletes "b,2" for example. Also, I cant write it with lines and that why im a bit confused and stuck... Thnks for all the helpers.
class Data:
def __init__(self):
print "are you ready?? :)"
def add_data(self, user_name, password):
add = open("user_data.txt", "a")
add.write(user_name + "," + password + ";")
add.close()
def show_file(self):
file = open("user_data.txt", "r")
print file.read()
file.close()
def erase_all(self):
file = open("user_data.txt", "w")
file.write("")
file.close()
def return_names(self):
file = open("user_data.txt", "r")
users_data = file.read()
users_data = users_data.split(";")
names = []
for data in users_data:
data = data.split(",")
names.append(data[0])
file.close()
return names
def is_signed(self, user_name):
names = self.return_names()
for name in names:
if user_name == name:
return True
return False
def is_password(self, user_name, password):
file = open("user_data.txt", "r")
users_data = file.read()
users_data = users_data.split(";")
for data in users_data:
data = data.split(",")
if data[0] == user_name:
if data[1] == password:
return True
file.close()
return False
def erase_user(self, user_name):
pass