python核心编程“第一个Python程序”makeTextFile.py中错误纠正
2013-03-19 16:03
330 查看
算是第一个原创博客吧
感觉蛮好的一个例子,makeTextFile.py中出现了错误,缩进不对,并且少了一句读入文件名的代码,现将修正后的代码贴出来供大家参考
蛮喜欢python的风格的,功能也不错,这学期有用到的地方,所以就学了一下,大家一起努力吧~
感觉蛮好的一个例子,makeTextFile.py中出现了错误,缩进不对,并且少了一句读入文件名的代码,现将修正后的代码贴出来供大家参考
蛮喜欢python的风格的,功能也不错,这学期有用到的地方,所以就学了一下,大家一起努力吧~
#!/usr/bin/env python 'makeTextFile.py -- create text file' import os ls = os.linesep # get filename while True: fname = raw_input('Enter file name: ') #需要添加的语句,并且需要缩进,后面的四条语句也需要缩进 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程序hello.py提示出现File "<stdin>",line 1错误
- Python学习第一个程序:python第一个程序hello.py提示出现File "<stdin>",line 1错误
- 运行python程序时出现错误“SyntaxError: Non-ASCII character '\xe8' in file variable.py on line 1, but no encod”
- [python]makeTextFile.py 和 readTextFile.py 脚本
- python使用web.py建立第一个hello world程序
- 配置caffe的python环境时make pycaffe提示fatal error: numpy/arrayobject.h No such file or directory解决方法
- 第一个python程序hello.py
- 对《Python核心编程》中“第一个Python程序”的改进
- 对《Python核心编程》中“第一个Python程序”的改进
- python出现中文错误:SyntaxError: Non-ASCII character '\xe7' in file car-training.py on line 7, but no encod
- python错误解决:SyntaxError: Non-ASCII character '\xd3' in file crawler.py
- 对于python的认识及python的第一个程序hello.py
- python错误:SyntaxError: Non-UTF-8 code starting with '\xcb' in file E:/Python/test.py on line 2
- Python核心编程之第一个Python程序
- makeTextFile.py
- makeTextFile.py 详细解析
- 2011-11-24 13:51 [错误]File "/usr/lib/python2.7/subprocess.py"
- 二,python第一个程序
- Exercise1:第一个Python程序
- Python与selenium环境安装以及第一个python和selenium程序,可作为入门第一课