文件操作

f = open("1.txt")  

abc = f.readable() #判断文件是否可读

print(abc)

 

f = open("1.txt")  

abc = f.read() #一次性读入全部内容

print(abc)

 

f = open("1.txt")  

abc = f.readline() #读入一行,包括换行符

print(abc)

 

f = open("1.txt")  

abc = f.read(10) #读入10个字符(文本模式),读入10个字节(二进制模式)

print(abc)

 

f = open("1.txt")  

abc = f.readline().strip() #readline通常和strip一起使用,去除换行符

print(abc)

 

f = open("1.txt")  

abc = f.readline().rstrip() #通常使用rstrip("\n") ,避免移除首尾的空白

print(abc)

 

f = open("1.txt")  

abc = f.readlines() #一次读出所有行

print(abc)

 

posted on 2018-03-07 16:14  一年级的小明同学  阅读(56)  评论(0)    收藏  举报

导航