for…in在python中的例子
2009-07-03 17:54
423 查看
#!/usr/bin/env python 'makeTextFile.py -- create text file' import os ls = os.linesep # get filename while True: if os.path.exists(fname): print"*** ERROR: '%s' already exists" % fname else: break # get file content (text) lines all = [] print "\nEnter lines ('.' by itself to quit).\n" # loop until user terminates input while True: entry = raw_input('> ') if entry == '.': break else: all.append(entry) # write lines to file with proper line-ending fobj = open(fname, 'w') fobj.writelines(['%s%s' % (x, ls) for x in all]) fobj.close() print 'DONE!'
相关文章推荐
- Python 列表推导式 if else for in join with as
- Python(5)使用for...in循环和列表推导式打印一个99乘法表
- gulp npm安装gulp-sass报错: checking for Python executable "python2" in the PATH
- 7.8-7.10 JLL实习日志-DjangoAPI+python+json,post for many records in a time
- How can I install Easy_Install for Python 2.6.4 in Mac OSX 10.4.11【转】
- 利用python进行数据分析——data = {i : randn() for i in range(7))
- how to write a DLL/SO in C/C++ for Python
- Python:列表中len、in、For的使用案例
- Non-Maximum Suppression for Object Detection in Python
- 《Thinking in java》第四版中的例子tupeinfo/SweetShop.java存在问题,全限定名;forName()方法
- “Cannot Save Setting” in pyCharm for python interpreter
- heap sort in python :-) just for fun
- python for in if 连着写与分开写的区别
- writing-plugins-for-gedit-3-in-python
- python机器学习实战之 Decision Tree For Titanic in Kaggle
- Python学习笔记十二:列表(4)--len 、in、For的使用
- python for android : 一个输入ISBN的查询书籍例子
- [Python] Check for None (Null) in Python
- Excel 2 Json For Python In Mac
- Python入门教程-13 for-in