Vote count:
0
I have the following python code:
#module1
from module2 import reader
def registration(userName, password, fileName, delimiter):
with open(fileName, 'a') as file:
file.write(userName + delimiter + password + '\n')
return reader(fileName, delimiter)
#module2
def reader(fileName, delimiter):
retVal = []
with open(fileName, 'r') as file:
for line in file:
pair = line.split(delimiter)
pair[1] = pair[1].strip()
retVal.append(pair)
return retVal
Now, what I should get is a list of lists that have the username and password strings. The reader does read the entries previously written, but doesn't read the one that was just added via the registration function. If I call the reader
function twice (one more time before the return), my registration function does return the correct list (with the newly appended user).
Any idea why this is happening?
asked 26 secs ago
Python: Can't read last appended lines in file
Aucun commentaire:
Enregistrer un commentaire