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

上一篇:php csv导出


下一篇:java Joda-Time 对日期、时间操作