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. Nlog从下载到使用例子

    第一.首先下载nlog.dll 下载地址:http://pan.baidu.com/s/1i3DQsV7 第二.添加nlog.ll的引用 第三.代码 private static Logger log ...

  2. Core Data数据持久性存储基础教程-备用

    摘要 就像我一直说的,Core Data是iOS编程,乃至Mac编程中使用持久性数据存储的最佳方式,本质上来说,Core Data使用的就是SQLite,但是通过一系列特性避免了使用SQL的一些列的麻 ...

  3. LeetCode_Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  4. shell 脚本FTP自动上传文件

    下面的脚本 会把本地的文本文件压缩后, 上传到FTP服务器上. 里面有一点小逻辑, 就是上传的文本文件 是 日期时间.txt 形式的, 一天写一个日志文件, 今天的文件不上传, 只上传 老的日志文件. ...

  5. Red Hat Enterprise Linux 7的新功能

     简介红帽最新版本的旗舰平台交付显著增强的可用性. 性能和可靠性. 丰富的新功能为架构. 系统管理员和开发人员提供所需的资源以更高效地进行创新和管理.架构师: 红帽® 企业 Linux® 7 适合 ...

  6. 通用Makefile

    本文推荐了一个用于对 C/C++ 程序进行编译和连接以产生可执行程序的通用 Makefile. 在使用 Makefile 之前,只需对它进行一些简单的设置即可:而且一经设置,即使以后对源程序文件有所增 ...

  7. 【czy系列赛】czy的后宫6 && bzoj1044 [HAOI2008]木棍分割

    题目描述 众所周知的是丧尸czy有很多妹子(虽然很多但是质量不容乐观QAQ),今天czy把n个妹子排成一行来检阅.但是czy的妹子的质量实在--所以czy看不下去了.检阅了第i个妹子会增加czy a[ ...

  8. Tomcat查看用户名密码

    在非安装版的tomcat中,可以在{解压路径}/conf/tomcat_users.xml 配置文件中找到,也可以自己添加新的用户

  9. IT技术如何转向销售创业

    广州 IT 网友  14:14:10 本人本科软件工程毕业,现在在一家公司做开发(不是很技术的那种),工作接近两年感觉自 己不适合这个行业,想换销售行业,不愿意在做技术.打算从事本行业的销售,老师给点 ...

  10. 话说GET与POST那点恩怨

    看过很多人写GET和POST之间的区别,为什么这么多人关注它们呢?因为它们是最常用的两种HTTP方法,之间有很多相同之处,也存在非常大的不同.首先了解一下HTTP方法: 什么是HTTP?     超文 ...