[Head First Python]4. summary
1- strip()方法可以从字符串去除不想要的空白符
(role, line_spoken) = each_line.split(":", 1)
line_spoken = line_spoken.strip()
2- print() BIF的file参数控制将数据发送/保存到哪里
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
if indent:
for tab_stop in range(level):
print("\t",end='', file = fn)
print(each_item, file = fn)
3- 会向except组传入一个异常对象,并使用as关键字赋至一个标示符
except IOError as err:
print('file error' + str(err))
except pickle.PickleError as perr:
print('pickle err' + str(perr))
4- str() BIF可以用来访问任何数据对象的串表示
5- locals() BIF返回当然作用域中的变量集合
try:
data = open ('missing')
print(data.read_line(),end = '')
except IOError as err:
print('file error' + str(err))
finally:
if 'data' in locals():
data.close()
try:
with open ('missing.txt','w') as data:
print("this is test",file = data)
except IOError as err:
print('file error' + str(err))
6- in 操作符用来检查成员关系
7- + 连接两个字符串
8- with 会自动处理所有已打开文件的关闭工作,即使出现异常也不例外, with也使用as关键字
9- sys.stdout 是python中"标准输出", 可以从标准库的sys模块访问
10- 标准库的pickle模块, 将python数据对象保存到磁盘及从磁盘恢复
11- pickle.dump() 函数将数据保存到磁盘
try:
with open('man.out', 'wb') as man_out, open('other.out','wb') as other_out:
pickle.dump(man, man_out)
pickle.dump(other, other_out)
12- pickle.load() 函数从磁盘恢复数据
new_man = []
try:
with open('man.out', 'rb') as man_file:
new_man = pickle.load(man_file)
[Head First Python]4. summary的更多相关文章
- [Head First Python]6. summary
1- 字典-内置数据结构,数据值与键值关联 键-字典中查找部分 值-字典中数据部分 使用dict()工厂函数或者只用{}可以创建一个空字典 >>> list = {} >> ...
- Python Syntax Summary
# _*_ coding: utf-8 _*_ """########################################################## ...
- [Head First Python]5. summary
1- "原地"排序-转换后替换 >>> list = [2,1,3] >>> list.sort() >>> list [1, ...
- Python初体验
今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...
- C#调用Python脚本打印pdf文件
介绍:通过pdf地址先将文件下载到本地,然后调用打印机打印,最后将下载的文件删除. 环境:windows系统.(windows64位) windows系统中安装python3.6.2环境 资料: O ...
- 05基于python玩转人工智能最火框架之TensorFlow基础知识
从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...
- Python实例--C#执行Python脚本,传参
# -*- coding: utf-8 -*- # 第一行的目的,是为了让代码里面,可以有中文注释信息. (否则要运行报错) # 这个 Python 脚本, 用于被 C# 来调用. # 简单测试 He ...
- Cheatsheet: 2013 09.22 ~ 09.30
Other Python basics summary Another article about big O notation Mobile Getting Started with PhoneGa ...
- TensorFlow应用实战 | TensorFlow基础知识
挺长的~超出估计值了~预计阅读时间20分钟. 从helloworld开始 mkdir 1.helloworld cd 1.helloworldvim helloworld.py 代码: # -*- c ...
随机推荐
- open_basedir restriction in effect. File() is not within the allowed path(s)
目前发现eaccelerator安装之后如果php.ini中设置open_basedir将导致open_basedir的一些报错(open_basedir restriction in effect. ...
- linux虚拟机网络连接模式 bridged, host-only, NAT
最近安装了fedora9.0,却一直不能连接到外网,我用的是3G无线网卡上网的,起初以为是linux不支持3G无线方式的,可后来装了虚拟机ubuntu却可以上网,在后来用有ADSL网络连接的电脑安装f ...
- hdu 1732 Push Box
http://acm.hdu.edu.cn/showproblem.php?pid=1732 推箱子和游戏规则一样. #include <cstdio> #include <cstr ...
- TOMCAT之性能跟踪入门
先扫清前面的障碍,再慢慢进入核心 转一下网上的我关心的话题,实施起来 ~~~ 使用Nginx作为反向代理时,Tomcat的日志记录的客户端IP就不在是真实的客户端IP,而是Nginx代理的IP.要解决 ...
- BZOJ 1070 修车(最小费用流)
链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1070 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术 ...
- Powershell 执行外部命令
Powershell 执行外部命令 724 11月, 2011 在 Powershell tagged Powershell教程 / 程序 by Mooser Lee本文索引[隐藏]1通过nets ...
- PERL 实现微信登录
get 请求: https://login.weixin.qq.com/jslogin? appid=wx782c26e4c19acffb &redirect_uri=https%3A%2F% ...
- Html 加载音乐代码mp3
<object data="__PUBLIC__/home/mp3/media.mp3" type="application/x-mplayer2" wi ...
- cocos2d-x3.2中怎样优化Cocos2d-X游戏的内存
在游戏项目优化中都会碰到一个问题,怎样既能降低内存又能尽量降低包的大小?在实际项目中有些经验分享一下,其实2D游戏中最占内存的就是图片资源,一张图片使用不同的纹理格式带来的性能差异巨大.下表是我在IO ...
- OJ2.0userInfo页面Modify逻辑bug修复,search功能逻辑实现
这周的主要任务:userInfo页面Modify逻辑bug修复,search功能逻辑实现. (一)Modify逻辑bug修复: 这里存在的bug就是在我们不重置password的时候依照前面的逻辑是不 ...