- 61
- 0
- 约1万字
- 约 12页
- 2017-01-29 发布于重庆
- 举报
python核心编程第二版课后题答案第九章
9.11 练习?9–1. 文件过滤. 显示一个文件的所有行, 忽略以井号( # )开头的行. 这个字符被用做Python , Perl, Tcl, 等大多脚本文件的注释符号.附加题: 处理不是第一个字符开头的注释.with open(data.txt) as fobj: for eachline in fobj: if not eachline.startswith(#): print eachline附件题看不懂。。。。。9–2. 文件访问. 提示输入数字 N 和文件 F, 然后显示文件 F 的前 N 行.filename = raw_input(please enter the filename:)num = int(raw_input(please enter the line number:))for eachline in open(filename): if num: print eachline num -= 1 else: break程序输出: please enter the filename:data.txtplease enter the line number:5#第一行hello world#第二行i love this world#第三行9–3. 文件信息.
原创力文档

文档评论(0)