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的更多相关文章

  1. [Head First Python]6. summary

    1- 字典-内置数据结构,数据值与键值关联 键-字典中查找部分 值-字典中数据部分 使用dict()工厂函数或者只用{}可以创建一个空字典 >>> list = {} >> ...

  2. Python Syntax Summary

    # _*_ coding: utf-8 _*_ """########################################################## ...

  3. [Head First Python]5. summary

    1- "原地"排序-转换后替换 >>> list = [2,1,3] >>> list.sort() >>> list [1, ...

  4. Python初体验

    今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...

  5. C#调用Python脚本打印pdf文件

     介绍:通过pdf地址先将文件下载到本地,然后调用打印机打印,最后将下载的文件删除. 环境:windows系统.(windows64位) windows系统中安装python3.6.2环境 资料: O ...

  6. 05基于python玩转人工智能最火框架之TensorFlow基础知识

    从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...

  7. Python实例--C#执行Python脚本,传参

    # -*- coding: utf-8 -*- # 第一行的目的,是为了让代码里面,可以有中文注释信息. (否则要运行报错) # 这个 Python 脚本, 用于被 C# 来调用. # 简单测试 He ...

  8. Cheatsheet: 2013 09.22 ~ 09.30

    Other Python basics summary Another article about big O notation Mobile Getting Started with PhoneGa ...

  9. TensorFlow应用实战 | TensorFlow基础知识

    挺长的~超出估计值了~预计阅读时间20分钟. 从helloworld开始 mkdir 1.helloworld cd 1.helloworldvim helloworld.py 代码: # -*- c ...

随机推荐

  1. 【5】python核心编程 第八章-条件和循环

    1.=== range() 的完整语法=== Python 提供了两种不同的方法来调用 range() . 完整语法要求提供两个或三个整数参数: range(start, end, step =1) ...

  2. Java笔记--Java的List、Iterator用法

    1. List的使用 准备知识: List继承自Collection接口.List是一种有序集合,List中的元素可以根据索引(顺序号:元素在集合中处于的位置信息)进行取得/删除/插入操作. 跟Set ...

  3. 正式学习react(二)

    今天把上一篇还没学习完的 webpack部分学习完: 之前有说过关于css的webpack使用.我们讲了 ExtractTextPlugin 来单独管理css讲了module.loaders下关于 c ...

  4. 几种TCP连接中出现RST的情况

    http://blog.chinaunix.net/uid-24517549-id-3991141.html http://blog.chinaunix.net/uid-24517549-id-399 ...

  5. LeetCode_Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  6. Eclipse配置JDK的源代码的src.zip

    Eclipse配置JDK的源代码的src.zip包很简单.只需要简单的几个步骤. 1.点 “window”-> “Preferences” -> “Java” -> “Install ...

  7. VS2012 快捷键 VS Resharper 设置

    原文 http://www.cnblogs.com/skyangell/archive/2013/03/24/2979835.html 一直用Resharper插件,最近发现Ctrl+E,C快捷见被R ...

  8. 【转】Linux中history历史命令使用方法详解

    原文网址:http://os.51cto.com/art/201205/335040.htm 当你在玩Linux的时候,如果你经常使用命令行来控制你的Linux系统,那么有效地使用命令历史机制将会使效 ...

  9. windows nfs server for linux

    摘要 在开发嵌入式系统的过程中,为了方便调试与文件共享,需要使用到nfs,即网络文件系统,这位板子的调试测试带来了很大的方便.之前在linux系统下开发,与ARM11核心板 linux系统对接共享也比 ...

  10. C++指针初始化总结

    1.字符指针的初始化 在c语言中 "string"保存的就是首个字符所在的地址  所以可以把 字符串常量"string" 赋值给指针 char *p;  &qu ...