Python cookbook - 读书笔记
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 - 读书笔记的更多相关文章
- Linux Shell Scripting Cookbook 读书笔记 1
本系列文章为<Linux Shell Scripting Cookbook>的读书笔记,只记录了我觉得工作中有用,而我还不是很熟练的命令 书是很好的书,有许多命令由于我比较熟悉,可能就没有 ...
- python cookbook学习笔记 第一章 文本(1)
1.1每次处理一个字符(即每次处理一个字符的方式处理字符串) print list('theString') #方法一,转列表 结果:['t', 'h', 'e', 'S', 't', 'r', 'i ...
- python文件读书笔记
一.打开文件 1 f=open('text.txt',r) 二.读取文件 print(f.read) 三.关闭文件 f.close() 比较好用的是运用with with open('text.tx ...
- python 进阶读书笔记2 -- python魔法函数
#!/usr/bin/env python# -*- coding: utf-8 -*- class student: def __init__(self, name_list): self.stud ...
- python 进阶读书笔记1 -- 理解python一切皆对象
理解python一切皆对象: 1.所有的类都是由type创建的 2.所有的类的基类都是object 3.type是类,也是实例,type的基类是object,type对象是由type创建的 4.obj ...
- 《流畅的python》读书笔记
流畅的python 第1章 python数据模型 ---1.1 一摞Python风格的纸牌 特殊方法,即__method__,又被称为魔术方法(magic method)或者双下方法(dunder-m ...
- python设计模式--读书笔记
GoF在其设计模式一书中提出了23种设计模式,并将其分为三类: 创建型模式 将对象创建的细节隔离开来,代码与所创建的对象的类型无关. 结构型模式 简化结构,识别类与对象间的关系,重点关注类的继承和组合 ...
- 《流畅的python》读书笔记,第一章:python数据模型
这本书上来就讲了魔法方法,也叫双下方法.特殊方法,通过两个例子对让读者了解了双下方法的用法,更重要的是,让我一窥Python的语言风格和给使用者的自由度. 第一个例子:一摞Python风格的纸牌: i ...
- Linux Shell Scripting Cookbook 读书笔记 2
cat,script,find, xargs, tr, tmp文件,字符串截取,批量文件重命名,固定大小文件,自动化交互 1. cat的用法 压缩连续的空白行 cat -s file 也可以用tr,将 ...
随机推荐
- dragsort拖动插件的使用
<!DOCTYPE html><html><head> <title>DragSort Example</title> <meta c ...
- GridView 服务端控件添加 js
针对服务端控件的 CommandField “Delete” 添加 js $("#GridView1").find("a").each( function() ...
- [转载]C# ListView用法详解
一.ListView类 1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设 ...
- PAT-乙级-1052. 卖个萌 (20)
1052. 卖个萌 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 萌萌哒表情符号通常由“手”.“眼”. ...
- ubuntu下opencv2.4.9安装测试
ubuntu下opencv2.4.9安装测试 whowhoha@outlook.com 一.依赖包安装 1. build-essential 软件包 sudo apt-get install bui ...
- Caffe训练好的网络对图像分类
对于训练好的Caffe 网络 输入:彩色or灰度图片 做minist 下手写识别分类,不能直接使用,需去除均值图像,同时将输入图像像素归一化到0-1直接即可. #include <caffe/c ...
- 消除SDK更新时的“https://dl-ssl.google.com refused”异常
原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“https://dl-ssl.google.com ref ...
- java 中 String 类的几个问题
首先,我们要搞清楚,在java中,引用和基本数据类型是存储在栈中的.而对象是存储在堆中的. 只有一个例外,就是String对象. 例如: String str1="test"; S ...
- http://my.oschina.net/u/1185331/blog/502350
http://my.oschina.net/u/1185331/blog/502350
- 什么是struts2?
一.我对struts2的理解. 1.struts2 是一个按MVC模式设计放入web层框架,其实它就是一个servlet.这个servlet命名为ActionServlet,或者是它的一个子类.它的工 ...