Reputation: 33
I am new to Python and am following a tutorial on how to write/read text files here. But I ran into an issue where when writing a file, it does not create another line, but just writes directly after the first one. I attached my code below, any help is appreciated greatly!
import os
import sys
def generate_cdat():
file = open("documents/pytho/login/cdat.txt", "w")
file.write("username[usr]")
file.write("userpass[1234]")
file.close()
def getCredentials(checkUsrName, checkUsrPass):
file = open("documents/pytho/login/cdat.txt", "r")
recievedUsrName = file.readline(1)
recievedUsrPass = file.readline(2)
if checkUsrName in recievedUsrPass:
print("recieved username")
print("started program")
print("checking for constant data file")
path = "cdat.txt"
if os.path.exists(path):
print("Constant data found, setting up")
else:
print("Constant data not found, creating constant data.")
generate_cdat()
print("starting login")
logingIn = True
while logingIn == True:
getUsrName = input("Enter username: ")
getUsrPass = getpass.getpass("Enter password: ")
checkCredentials(getUsrName, getUsrPass)
Upvotes: 1
Views: 13116