文件读写

文件读写#

# File IO
some_sentences = '''\
I love learning python
because python is fun
and also easy to use
'''

# Open for 'w'riting
f = open('../_tmp/py_open_w.txt', 'w')

# Write text to File
f.write(some_sentences)
f.close()

# If not specifying mode, 'r'ead mode is default
f = open('../_tmp/py_open_r.txt')
while True:
    line = f.readline()
    # Zero length means End Of File
    if len(line) == 0:
        break
    print(line)

# close the File
f.close
I love learning python

because python is fun

and also easy to use
<function TextIOWrapper.close()>