python学习手册笔记--第9章--元组文件及其他
来源:互联网 发布:js获取元素name属性值 编辑:程序博客网 时间:2024/06/18 14:43
元组:
初始化:yz=1,32,'fd' <==> yz=(1,32,'fd')
t=tuple('cai')>>>('c','a','i')
t.index(x) t.count(x) t.index(x,k):第k个x的位置
(1,2)+(3,4)>>>(1,2,3,4)
yz=(40)>>>40 yz=(40,)>>>(40,)
转列表:tmp=list(t)>>>['c','a','i']
t=tuple(tmp)>>>('c','a','i')
元组只是顶层内容不能改变:
t=(1,[2,3],4) t[1][0]='cai'>>(1,['cai',3],4) right
文件:
常见运算
output=open(r'c:\cai','w')
input=open('data','r') <==> input=open('data')
aString=input.read() 把整个文件读进一字符串
aString=input.read(N) 读取N 个字节字符串
aString=input.readline() 读一行
aList=input.readlines() 读取整个文件->字符串列表
output.write(aString) output.writelines(alist)
output.close() output.flush()
anFile.seek(N) 修改位置移到N
open('f.bin', 'rb')
'a' 代表追加
'+' 可读可写
temp=output.readline().rstrip() 去掉换行符
eval(XX) 将XX转换为普通列表或字典,而非字符串
pickle存储python的原生对象
f=open('file.pkl','wb') d={'a':1,'b':2}
import pickle pickle.dump(d,f)
f.close()
读取:f=open('file.pkl','rb') e=pickle.load(f)>>>d
打包二进制数: data=struct.pack('abc',43,XX)
解析二进制数: values=struct.unpack(data)
字典的比较:通过.items() sorted后比较
isinstance([1],list)>>>True
循环数据结构
l=['cai'] l.append(l)>>>['cai',[...]]
初始化:yz=1,32,'fd' <==> yz=(1,32,'fd')
t=tuple('cai')>>>('c','a','i')
t.index(x) t.count(x) t.index(x,k):第k个x的位置
(1,2)+(3,4)>>>(1,2,3,4)
yz=(40)>>>40 yz=(40,)>>>(40,)
转列表:tmp=list(t)>>>['c','a','i']
t=tuple(tmp)>>>('c','a','i')
元组只是顶层内容不能改变:
t=(1,[2,3],4) t[1][0]='cai'>>(1,['cai',3],4) right
文件:
常见运算
output=open(r'c:\cai','w')
input=open('data','r') <==> input=open('data')
aString=input.read() 把整个文件读进一字符串
aString=input.read(N) 读取N 个字节字符串
aString=input.readline() 读一行
aList=input.readlines() 读取整个文件->字符串列表
output.write(aString) output.writelines(alist)
output.close() output.flush()
anFile.seek(N) 修改位置移到N
open('f.bin', 'rb')
'a' 代表追加
'+' 可读可写
temp=output.readline().rstrip() 去掉换行符
eval(XX) 将XX转换为普通列表或字典,而非字符串
pickle存储python的原生对象
f=open('file.pkl','wb') d={'a':1,'b':2}
import pickle pickle.dump(d,f)
f.close()
读取:f=open('file.pkl','rb') e=pickle.load(f)>>>d
打包二进制数: data=struct.pack('abc',43,XX)
解析二进制数: values=struct.unpack(data)
字典的比较:通过.items() sorted后比较
isinstance([1],list)>>>True
循环数据结构
l=['cai'] l.append(l)>>>['cai',[...]]
- python学习手册笔记--第9章--元组文件及其他
- 【Python 学习手册笔记】元组、文件及其他
- 《Python学习手册》学习笔记(9)之第9章元组、文件及其他(关键词:编程语言/Python/元组/文件)
- Python学习笔记(七):元组、文件及其他类型
- 《Python学习手册》学习笔记——第4章
- 《Python学习手册》学习笔记——第5章
- python学习手册笔记--第4章--对象类型
- python学习手册笔记--第7章--字符串
- python学习手册笔记--第8章--列表与字典
- python学习手册笔记--第12~13,15章
- python学习手册笔记--第14.20章--迭代器和解析
- python学习手册笔记--第16~19章--function_base
- python学习手册笔记--第21~24章
- python学习手册笔记--第25,28,30,32章
- python学习笔记(第6章 序列:字符串,列表和元组)(一)
- python-元组学习笔记
- Python元组学习笔记
- PYTHON-学习笔记:元组
- python学习手册笔记--第7章--字符串
- expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
- python学习手册笔记--第8章--列表与字典
- No 126 · 2, 8, 10, 16进制转换.
- 如何解决css样式表在不同浏览器中显示效果不同的问题
- python学习手册笔记--第9章--元组文件及其他
- 关于Excel Spreadsheet 对象的属性的定义
- Bingo卡片案例笔记【一】、建立一个bingo卡片表格
- 美国的时间格式 -- 复杂格式的日期转换 使用Date.parse(“复杂的格式”)方法。
- python学习手册笔记--第10章--语句简介--第11章--复制_表达式_打印
- C# 子窗体中调用父窗体中的方法(或多窗体之间方法调用)
- Tomcat 系统架构与设计模式,第 1 部分: 工作原理
- python学习手册笔记--第12~13,15章
- python学习手册笔记--第14.20章--迭代器和解析