创建一个名为mypython.txt文件,文件中包含三行字符串,分别为: wherethereisawill,>thereisaway.>有志者事竟成。以只读方式读取打开该文件,并分别用三种方式读取全部内容,输出到屏幕上。
file_object = open('mypython.txt','r')print(file_object.read())file_object.close() file_object = open('mypython.txt','r')print(file_object.readline())print(file_object.readline())print(file_object.readline())file_object.close() file_object = open('mypython.txt','r')print(file_object.readlines())file_object.close()