Python File IO
'''
Created on 2011-4-30
@author: xuqiang
'''
# open file
# open(file, mode)
# file : the file to be opened
# mode : open file mode, 'r' the file will only be read
# 'w' only writing and existing file with the same name will be erased
# 'a' opens the file for appending
# 'r+' read & write
# 'b' on windows, use this flag to indicate that open file binary, eg 'wb', 'r+b'
f = open('./file.txt', 'r+');
# read the first line
print(f.readline());
# read the left lines
print(f.readlines());
# tell the file pointer position
print("now the file position is ", f.tell());
# set the file pointer to 0L
f.seek(0);
# close the file
f.close();
Created on 2011-4-30
@author: xuqiang
'''
# open file
# open(file, mode)
# file : the file to be opened
# mode : open file mode, 'r' the file will only be read
# 'w' only writing and existing file with the same name will be erased
# 'a' opens the file for appending
# 'r+' read & write
# 'b' on windows, use this flag to indicate that open file binary, eg 'wb', 'r+b'
f = open('./file.txt', 'r+');
# read the first line
print(f.readline());
# read the left lines
print(f.readlines());
# tell the file pointer position
print("now the file position is ", f.tell());
# set the file pointer to 0L
f.seek(0);
# close the file
f.close();
如果您觉得不错,欢迎扫码支持下。
作者:许强1. 本博客中的文章均是个人在学习和项目开发中总结。其中难免存在不足之处 ,欢迎留言指正。 2. 本文版权归作者和博客园共有,转载时,请保留本文链接。