每天CookBook之Python-073

  • 文件读写

with open('../passwd.txt' , 'rt') as f:
    data = f.read()
    print(data)

with open('../passwd.txt', 'rt') as f:
    for line in f:
        print(line)

with open('somefile.txt', 'wt') as f:
    f.write("111")

with open('../passwd.txt', 'rt', encoding='latin-1') as f:
    print(f.read())
posted @ 2016-07-24 12:21  4Thing  阅读(80)  评论(0编辑  收藏  举报