Python, writing an integer to a '.txt' file
Write
result = 1
f = open('output1.txt','w') # w : writing mode / r : reading mode / a : appending mode
f.write('{}'.format(result))
f.close()
Read
f = open('output1.txt', 'r')
input1 = f.readline()
f.close()
print(input1)
I think it's simpler doing:
number = 1337
with open('filename.txt', 'w') as f:
f.write('%d' % number)
But it really depends on your use case.