Advertisement

Python程序设计基础5:Python文件使用——遍历一个文件夹中的所有图片

阅读量:

文件的处理方式非常普遍。为了更好地理解一般TXT文档的操作流程,请通过基本的例子来认识。

生成一个TXT文本文件,在该文件中记录学生的基本信息项。具体包括学生的姓名、性别以及居住地址。

代码:

11 #!/usr/bin/env python
10 # encoding: utf-8
9
8 f=open('filecreat.txt','w')
7 f.write('name'+' '+'sex'+' '+'cellphone'+' '+'address'+'\n')
6 flag=True
5 while flag:
4 name=raw_input('please input a name:')
3 sex=raw_input('please input the sex:')
2 cellphone=raw_input('please input the cellphone number:')
1 address=raw_input('please input the address:')
12 s=name+' '+'sex'+' '+'cellphone'+' '+'address'\n
1 f.write(s)
2 flag=input('will you continue?(yes/no):')\n
3 f.clo

全部评论 (0)

还没有任何评论哟~