f open( text.txt , r ) #打开文件 不存在就新建 存在就覆盖,默认为r
#f.write( hello world,fuck you! )
content f.read(5) #开始在头部 每次执行向后移动
print(content)
content f.read(5)
print(content)
content3 f.readlines() #一次性读取每行为列表
print((content3))
for temp in content3:
print( %d:%s %(i,temp))
f.close()
#异常处理
#捕获异常
print( - *10, text1 , - *10)
f open( t123t.txt , r )#打开不存在文件
print( - *10, text2 , - *10)
print(num123123)
#except (NameError,IOError): #文件没找到属于IO异常
# print( 有点问题哦 ) #捕获后展示代码
except Exception as result:
print(result)