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

前端 未结 5 1236
礼貌的吻别
礼貌的吻别 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:03

    With python 2, you can also do:

    number = 1337
    
    with open('filename.txt', 'w') as f:
      print >>f, number
    

    I personally use this when I don't need formatting.

提交回复
热议问题