第3章 python3基础 第一个python3程序
2015-01-17 01:11
169 查看
#!/usr/bin/env python3 #第一个python3程序 #书本实例3.1 import os #导入os模块 newline = os.linesep #这里定义系统的换行符 while True: filename = input("Please input a filename:") if os.path.exists(filename): #如果文件存在 print('The filename exists!Please input another filename!') else: break #如果输入的文件不存在, 那就跳出循环 filedata = [] #定义一个列表, 用于保存用户输入, 最后读取进文件中 print('Please input to %s :' % filename) while True: #当用户输入的不是#字符时, 就一直循环 userinput = input('>') if userinput != '#': filedata.append(userinput) else: break #打开文件, 把列表中的值写进去再保存 fileopen = open(filename, 'w+') fileopen.writelines(['%s%s' % (inputdata, newline) for inputdata in filedata] ) fileopen.close() print('DONE')
相关文章推荐
- 第一个Python程序
- 人生的第一个Python程序
- 第一个python的GUI程序
- [转载]看完《python简明教程》笔记及第一个python程序
- 看完《python简明教程》笔记及第一个python程序
- Python的第一个程序
- 我的第一个Python程序--批量生成Oracle DDL文件
- 深入Python3 (Dive Into Python3)笔记1--你的第一个 Python 程序
- Python 研究(Dive Into Python)笔记1--第2章 第一个 Python 程序
- 第一个 Python 程序
- 开始学习python了,第一个程序是一个逆波兰式的表达式分析器
- 第一个python 程序
- 第一个python CGI程序——hello,world
- 第一个python程序
- 第一个python程序-blog数目统计
- 我的第一个python程序-新浪新闻阅读器
- 第一个Python程序
- 我的第一个Python小程序
- 第一个python程序
- Python 写的第一个算法程序,果然很强大