import os#导入标准库“os”
print(os.getcwd())#当前的工作目录os.chdir("HeadFirstPython")#切换文件夹
os.chdir("chapter3")
os.getcwd()
man = []
other = []
try:
data = open("sketch.txt")
for each_line in data:
try:
(role,line_spoken) = each_line.split(":",1)
line_spoken = line_spoken.strip()
if role == "Man":
man.append(line_spoken)
elif role == "Other Man":
other.append(line_spoken)
except ValueError:
pass
data.close()
except IOError:
print("The data file is missing!")
print(man)
print(other)