Before:

python built-in function: docs

我只想学function map(), THIS  - 摘: map(foo, seq) is equivalent to [ foo(x) for x in seq]

               - (看这个帖子,我好像明白了什么。好像第一次明白了,什么是“函数式编程”。)

1.9 - 简化字符串的 translate 方法的使用

WAIT- -!

1.10 - 过滤字符串中不属于制定集合的字符

  1. 利用string.translate()处理中文,必须使用unicode。ASCII不能处理中文。

    这个问题花了我一个上午,哈哈,THIS。

#! /usr/bin/python
#Filename: translate.py transTable = { ord(''): u'一', ord(''): u'二'}
unicodeStr = u''
print unicodeStr.translate(transTable)

1.13 - 访问子字符串

  1. Python struct

struct.unpack_from(fmt, buffer[, offset=0])

Unpack the buffer according to the given format. The result is a tuple even if it contains exactly one item. The buffer must contain at least the amount of data required by the format (len(buffer[offset:]) must be at least calcsize(fmt)).

struct.calcsize(fmt)

Return the size of the struct (and hence of the string) corresponding to the given format.

>>> import struct
>>> baseformat = '5s 3x 8s 8s'
>>> theline = ''
>>> numremain = len(theline) - struct.calcsize(baseformat)
>>> format = '%s %ds' % (baseformat, numremain)
>>> format
'5s 3x 8s 8s 6s'
>>> l, s1, s2, t = struct.unpack(format, theline)
>>> print l, s1, s2, t
12345 90123456 78901234 567890

1.18 - 一次完成多个替换

关键是 import re。 Python的 正则表达式re 怎么用? THIS

END

Python cookbook - 读书笔记的更多相关文章

  1. Linux Shell Scripting Cookbook 读书笔记 1

    本系列文章为<Linux Shell Scripting Cookbook>的读书笔记,只记录了我觉得工作中有用,而我还不是很熟练的命令 书是很好的书,有许多命令由于我比较熟悉,可能就没有 ...

  2. python cookbook学习笔记 第一章 文本(1)

    1.1每次处理一个字符(即每次处理一个字符的方式处理字符串) print list('theString') #方法一,转列表 结果:['t', 'h', 'e', 'S', 't', 'r', 'i ...

  3. python文件读书笔记

    一.打开文件 1 f=open('text.txt',r)  二.读取文件 print(f.read) 三.关闭文件 f.close() 比较好用的是运用with with open('text.tx ...

  4. python 进阶读书笔记2 -- python魔法函数

    #!/usr/bin/env python# -*- coding: utf-8 -*- class student: def __init__(self, name_list): self.stud ...

  5. python 进阶读书笔记1 -- 理解python一切皆对象

    理解python一切皆对象: 1.所有的类都是由type创建的 2.所有的类的基类都是object 3.type是类,也是实例,type的基类是object,type对象是由type创建的 4.obj ...

  6. 《流畅的python》读书笔记

    流畅的python 第1章 python数据模型 ---1.1 一摞Python风格的纸牌 特殊方法,即__method__,又被称为魔术方法(magic method)或者双下方法(dunder-m ...

  7. python设计模式--读书笔记

    GoF在其设计模式一书中提出了23种设计模式,并将其分为三类: 创建型模式 将对象创建的细节隔离开来,代码与所创建的对象的类型无关. 结构型模式 简化结构,识别类与对象间的关系,重点关注类的继承和组合 ...

  8. 《流畅的python》读书笔记,第一章:python数据模型

    这本书上来就讲了魔法方法,也叫双下方法.特殊方法,通过两个例子对让读者了解了双下方法的用法,更重要的是,让我一窥Python的语言风格和给使用者的自由度. 第一个例子:一摞Python风格的纸牌: i ...

  9. Linux Shell Scripting Cookbook 读书笔记 2

    cat,script,find, xargs, tr, tmp文件,字符串截取,批量文件重命名,固定大小文件,自动化交互 1. cat的用法 压缩连续的空白行 cat -s file 也可以用tr,将 ...

随机推荐

  1. JQuery,UIbootstrap风格弹出层

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <met ...

  2. 让你网页同时兼容FireFox和IE

    CSS 兼容要点:DOCTYPE 影响 CSS 处理 FireFox: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行. FireFox: b ...

  3. uva 10330 最大流

    拆点  将节点 i 的容量拆成从 i 到 i+n 的边的容量 套用最大流模板 ac #include <cstdio> #include <cstdlib> #include ...

  4. spoj 78

    数学  组合 隔板法 #include <iostream> #include <cstring> #include <cstdio> #include <s ...

  5. 140304笔记, mysql 更改自动增长字段值的重新设定

    1. 存在同名的或不同的namespace交错情况. Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result m ...

  6. NGINX的奇淫技巧 —— 3. 不同域名输出不同伺服器标识

    NGINX的奇淫技巧 —— 3. 不同域名输出不同伺服器标识 ARGUS 1月13日 发布 推荐 0 推荐 收藏 6 收藏,707 浏览 大家或许会有这种奇葩的需求...要是同一台主机上, 需要针对不 ...

  7. Node.js 4.0.0:灵雀云和 OneAPM 的整合测试

    关于 Node.js 4.0.0 稳定版刚刚推出,备受期待,迫不及待地想用它写点东西:此外,要把 Demo 放到 Internet 上得有一个公网 IP ,看到灵雀云挺不错的而且提供域名解析,简直业界 ...

  8. [转载]Spring Java Based Configuration

    @Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the ...

  9. POJ 3273

    Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12122   Accepted: 4932 ...

  10. 【转载】synchronized 与 Lock 的那点事

    最近在做一个监控系统,该系统主要包括对数据实时分析和存储两个部分,由于并发量比较高,所以不可避免的使用到了一些并发的知识.为了实现这些要求,后台使用一个队列作为缓存,对于请求只管往缓存里写数据.同时启 ...