07 2017 档案

摘要:1.使用IDLE的异常信息: try: data=open('missing.txt') print(data.readline(),end='') """为异常对象给定一个名,然后作为错误消息的一部分""" except IOError as err: """使用str()BIF要求异常对象表现为 阅读全文
posted @ 2017-07-21 18:06 秋水潺流 阅读(231) 评论(0) 推荐(0)
摘要:1.将打印出来到台词保存到文件中,需要如下步骤: 1)创建一个空列表,名为man 2)创建一个空列表,名为other 3)增加一行代码,删除spoken_line不必要到空白符 4)给出条件和代码,根据role的值将spoken_line添加到适当到列表中 5)在屏幕输出各个列表(man和other 阅读全文
posted @ 2017-07-21 15:46 秋水潺流 阅读(550) 评论(0) 推荐(0)
摘要:1.错误处理 data=open('sketch.txt') for each_line in data: try: (role,spoken_line)=each_line.split(':',1) print(role,end='') print(' said:',end='') print(s 阅读全文
posted @ 2017-07-21 11:33 秋水潺流 阅读(201) 评论(0) 推荐(0)
摘要:1.python切换目录基本操作 >>>import os >>>os.getcwd() 获取当前工作目录(current working dirctory) >>>os.chdir('......') 切换到包含要打开的文件的目录 2.打开数据文件,读取文件第一个数据行 data=open('sk 阅读全文
posted @ 2017-07-11 18:29 秋水潺流 阅读(188) 评论(0) 推荐(0)
摘要:1.用循环处理一个嵌套列表 def print_lol(the_list): for each_item in the_list: if isinstance(each_item,list): print_lol(each_item) else: print(each_item) 注:1).这个函数 阅读全文
posted @ 2017-07-11 17:07 秋水潺流 阅读(349) 评论(0) 推荐(0)
摘要:列表的基本操作: 1.定义一个列表 cast=["xiaoming","xiaohua","xiaomei","xiaobai"] 2.使用len()BIF得出列表中的数据项,访问列表数据 1) print(len(cast)) 2)print(cast[1]) 3.在列表末尾添加一个数据项 cas 阅读全文
posted @ 2017-07-10 11:27 秋水潺流 阅读(194) 评论(0) 推荐(0)