文件和异常
1.常量列表元组,(item1,itme2,item3),赋值后就不能改变
2.try:
code
except:
pass
3.
import os
os.chdir("F:\\book\\python\\headfirst python book&&code\\code\\chapter3")
try:
data=open("ssketch.txt")
for each_line in data:
try:
(role,line_spoken)=each_line.split(":",1)
print(role,end="")
print(" said: ",end="")
print(line_spoken)
except ValueError:
pass
data.close()
except IOError:
os.chdir("F:\\book\\python\\headfirst python book&&code\\code\\chapter3")
try:
data=open("ssketch.txt")
for each_line in data:
try:
(role,line_spoken)=each_line.split(":",1)
print(role,end="")
print(" said: ",end="")
print(line_spoken)
except ValueError:
pass
data.close()
except IOError:
print("file is missing")
4.BIF :
data.split() //拆分字符串
data.readline() //读出一行
data.seek(0) //设置位置
data.close() //关闭流