python读写文件脚本
来源:互联网 发布:杭州二手房成交数据 编辑:程序博客网 时间:2024/05/21 04:22
输入文件名与文件内容并创建这个文件:(参考python核心编程P52)
#/usr/bin/env pythonimport osls=os.linesepwhile True: fname=raw_input('input a filename\n') if os.path.exists(fname): print "ERROR: '%s' already exists" % fname else: breakall = []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!'
读文件:
#/usr/bin/env pythonfname=raw_input('Enter filename: ')printtry: fobj = open(fname,'r')except IOError, e: print "*** file open error:", eelse: for eachLine in fobj: print eachLine, fobj.close()
1 0
- python读写文件脚本
- Python open读写文件实现脚本
- python写的读写文件的脚本
- Python open读写文件实现脚本
- Python open读写文件实现脚本
- 一个简单的python读写文件脚本
- Python open读写文件实现脚本
- python--python读写文件
- shell 脚本读写处理文件
- Python读写Unicode文件
- python Ini文件读写
- Python读写文件
- Python读写文件
- Python读写ini文件
- Python读写文件
- Python读写文件
- Python文件的读写
- python读写文件
- Apriori、FP-Growth及Eclat算法
- PHP SOCKET通信
- 【c#】——值类型和引用类型
- 模板与泛型编程
- Android 防止多次点击事件
- python读写文件脚本
- Kafka设计要点
- pod install 遇到 :[MT] DVTAssertions: ASSERTION FAILURE in ……
- 求转置矩阵问题
- LeetCode Binary Tree Zigzag Level Order Traversal
- acm2058
- LightOJ 1043 - Triangle Partitioning【数学】
- 数据结构之栈和队列
- windows10安装Genymotion步骤