The content of a file is not written immediately to your harddisk. The content is stored in the files internal buffer and eventually given to your operating system wich in turn decides when to acctually persist your data on your haddrive.
More on file flushing (aka emptying the buffer to your disk): How often does python flush to a file?
It is better to use the with open(name, mode) as filehandle:
paradigm when writing.
Try:
with open('hardlopers.txt', 'a+') as infile:
while True:
naam = input('geef je naam:')
if naam:
infile.write(naam)
else:
break
# now its written - with open autocloses on leaving the block
with open("hardlopers.txt","r") as r:
t = r.read()
print("")
print(t)
Output:
geef je naam:a
geef je naam:b
geef je naam:c
geef je naam:d
geef je naam:
abced
See examples at: reading-and-writing-files