python入门第三天——文件/存储器
来源:互联网 发布:廊坊管家婆软件 编辑:程序博客网 时间:2024/09/21 08:16
##python:input /output(I/O)##很多时候,你会想要让自己的程序与用户交互,从用户##得到输入,然后打印一些结果##常用的是输入输出类型是处理文件,创建,读写文件的能力是##必须的##file:可以通过file类的对象来打开一个文件##注意:对文件的读写能力依赖于程序在打开文件时的指定模式##注意:当在完成对文件的一系列操作后,记住调用close()告诉python我们完成了对文件的使用# print help('file')poem = """ Programing is fun when the work is done if you wanna make your work also fun use Python!"""f = file("poem.txt",'w')f.write(poem)f.close()my = file('poem.txt','r')##如果要对文件操作需要调用file(),默认操作是可读while True: line = my.readline() if len(line) == 0: break print linemy.close()##文件名也就是指针,指向文件的存储的内存##读取文件时需要文件名来寻找file# 文件的三种模式:可读(r),可写(w),追加(a)# 文件的打印,readline()逐行来打印文件的内容##存储器:pickle ,使用它,可以在一个文件中存储任何python对象##之后依旧可以完成无缺的取出来,这被称为持久的存储对象import pickle as pfilename = 'fruit'List = ['apple','orange','banana']f=file(filename,'w')p.dump(List,f)f.close()del List #remove the list##read back from the storagef=file(filename)storedList = p.load(f)# while True:# line = f.readline()# if len(line) == 0:# break# print line
阅读全文
0 0
- python入门第三天——文件/存储器
- 三天入门Python---文件操作(第三天)
- python入门第三天——类
- python入门第三天——继承
- python入门第三天——赋值区别
- python学习——第三天
- Python Learning——第三天
- 21天学通python——第三天
- 三天入门Python---基本语法(第一天)
- 8天入门wpf—— 第三天 样式
- 8天入门wpf—— 第三天 样式
- 8天入门wpf—— 第三天 样式
- 8天入门wpf—— 第三天 样式
- 【转载】8天入门wpf—— 第三天 样式
- 8天入门wpf—— 第三天 样式
- php入门第三天
- web入门第三天
- Lucene第三天入门
- JDBC—综述
- CORS解决ajax跨域问题
- 使用Sql Developer调试Oracle步骤
- kettle 列转行的demo
- Apache Lucene初探
- python入门第三天——文件/存储器
- 关于Android Studio项目的Gradle构建 泡在网上的日子 / 文 发表于2016-02-16 12:16 第2500次阅读 Gradle 3 编辑推荐:稀土掘金,这是一个针对技术开发者的
- 如何掌握所有的程序语言?
- c++初始化列表的一些知识点
- C语言注释符号一本道来.md
- OpenCV图像旋转/改变亮度对比度/高斯滤波/改变宽高比
- 经典算法之Prim算法
- Java之数列最大值和最小值
- 01 十年的等待,换来最真诚的告白