Reading and Writing : open « File « Python Tutorial






f = open('test.txt', 'w')
f.write('Hello, ')
f.write('World!')
f.close()


f = open('test.txt', 'r')
print f.read(4)
print f.read()








12.9.open
12.9.1.Access Modes for File Objects
12.9.2.'r' is the default processing mode
12.9.3.Open a file for reading
12.9.4.Open a file for writing
12.9.5.Opening a Nonexistent File
12.9.6.Opening a File and check its mode
12.9.7.Reading and Writing