ive been searching for ages for a solution on my problem: When a user types in a name, which is already saved in a .txt file, it should print "true". If the username is not already existing it should add the name, the user typed in. The Problem is, that it even prints out true when the typed name is "Julia", but "Julian" is already in the list. I hope you get my point. I already read maaany solutions here on stackoverflow but nothing worked for me when working with a .txt file My code:
import mmap
username = input("username: ")
names_file = open("names_file.txt", "a")
paste = bytes(username, 'utf-8')
with open("names_file.txt", "rb", 0) as file, \
mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s:
if s.find(paste) != -1:
print("true")
else:
names_file.write("\n" + username)
print(username + " got added to the list")
names_file.close()