PYTHON---FILE IO
import pickle

shoplistfile = 'shoplist.data'
shoplist = ['apple', 'mango', 'carrot']

f = open(shoplistfile, 'wb')
pickle.dump(shoplist, f)
f.close()

del shoplist

f = open(shoplistfile, 'rb')
storedlist = pickle.load(f)
print(storedlist)

print()

poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
    use Python!
'''

f = open('poem.txt', 'w')
f.write(poem)
f.close()

f = open('poem.txt')
while  True:
    line = f.readline()
    if len(line) == 0:
        break
    print(line)
f.close()
PYTHON---FILE IO

PYTHON---FILE IO

相关文章:

  • 2021-09-01
  • 2021-11-16
  • 2021-06-14
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-10-28
  • 2022-12-23
  • 2021-07-16
  • 2021-04-13
  • 2021-12-27
  • 2021-09-27
  • 2021-07-14
相关资源
相似解决方案