with open(filename, 'a') as out: out.write(var + ' ')
with open(filename, 'a') as f: print(var, file=f)