《python核心编程第二版》第三章习题
来源:互联网 发布:淘宝代销分账 保証金 编辑:程序博客网 时间:2024/05/21 10:06
3.8-3.13 一起做了。。。。
下面是代码
# -*- coding: utf-8 -*- import osdef maketextfile(): ls = os.linesep while True: fname = raw_input('enter a name') if os.path.exists(fname): print "EOOOR : '%s' already exists" %fname else: break all = [] print "\nenter lines ('.'by itself to quit).\n" while True: entry = raw_input('>') if entry == '.': break else: all.append[entry] fobj = open(fname,'w') fobj.writelines(['%s%s'%(x,ls)for x in all]) fobj.close() print 'DONE!' def readtextfile(): ls = os.linesep while True: fname = raw_input('enter a name') try: fobj = open(fname,'r') except IOError , e: print "*** file open error:",e else: for eachline in fobj: print eachline.strip('\n') fobj.close() break def addtextfile(): ls = os.linesep while True: fname = raw_input('enter a name') try: fobj = open (fname,'a') except IOError,e: print 'file open error:',e else: all = [] while True: input = raw_input('enter your content') if input == '.': break else: all.append(input) fobj.writelines(['%s%s'%(x , ls) for x in all]) fobj.close() break if __name__=='__main__': while True: print 'make a text file:m' print 'read a text file:r' print 'add a text file:a' order = raw_input() if order == 'm': maketextfile() elif order == 'r': readtextfile() elif order == 'a': addtextfile() elif order == 'exit': break else: print 'enter error'
0 0
- 《python核心编程第二版》第三章习题
- python核心编程(第二版)习题_第三章
- Python核心编程(第三版)课后习题解答——第二章
- Python核心编程 第二版 第二章 部分习题解答
- python核心编程 第二版 第二章 习题
- python核心编程第二版第二章习题
- <python 核心编程第二版课后习题>第二章
- 《Python核心编程》第二版课后习题——第三章(记录自己做的习题,可能有误)
- python核心编程第二章习题
- Python核心编程第二章课后习题
- 《Python核心编程》第二章习题解答
- Python核心编程第二章习题
- 《Python 核心编程》 第三章习题 3.10
- Python核心编程(第二版) 第五章 课后习题(1)
- python核心编程 第二版 第五章 习题
- <Python核心编程 第二版> 第四章习题
- 《python 核心编程第二版第六章》习题
- 《python 核心编程第二版第六章》习题补充
- 【吐血整理】Hibernate常用的主键生成策略的原理、优缺点、应用场合
- MongoDB(3.0.2)在centos6.2(64位)下安装
- Scala讲座:函数式语言的体验
- cocosstudio 面板 和层 和 图片的触碰
- jqGrid学习笔记(2)
- 《python核心编程第二版》第三章习题
- php $0
- Android sdk content loader 0%的解决方案
- sax解析操作XML
- 桶排序及其应用
- 池化服务与非池化服务的区别
- java导出功能
- java单例模式
- Android模拟器没有键盘的解决方法,Android DPAD not enabled in AVD