Python, writing an integer to a '.txt' file

前端 未结 5 1257
礼貌的吻别
礼貌的吻别 2021-02-20 03:20

Would using the pickle function be the fastest and most robust way to write an integer to a text file?

Here is the syntax I have so far:

import pickle

p         


        
5条回答
  •  悲哀的现实
    2021-02-20 04:07

    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)
    

提交回复
热议问题