Pyke 简介 (3) :调制 Python 函数
对 Python 函数的"调制",是指对其做出合乎需求的设置。具体的调制方法,是将其参数设为固定值(常数)。
设定单一的参数值
原先的函数是这样的:
>>> def foo(cooked, standard):
... print "foo called with cooked: %s, standard: %s" % \
... (cooked, standard)
调用它:
>>> foo('a', 'b')
foo called with cooked: a, standard: b
不过,想要的是让这个函数的第一个参数,变成"调制参数",并且只剩下第二个参数。
通过 Python 标准库模块functools的类partial,可以做到。
>>> from functools import partial
用 partial 调制第一个参数:
>>> cooked1 = partial(foo, 'cooked_value1')
原函数 foo 的第一个参数,被调制成为函数 cooked1,foo 的第二个参数,成了 cooked1 的唯一参数。
>>> cooked1('value1')
foo called with cooked: cooked_value1, standard: value1
>>> cooked1('value2')
foo called with cooked: cooked_value1, standard: value2
可以用其他值,生成调制函数:
>>> cooked2 = partial(foo, 'cooked_value2')
>>> cooked2('value1')
foo called with cooked: cooked_value2, standard: value1
>>> cooked2('value2')
foo called with cooked: cooked_value2, standard: value2
原本一个函数,现在调制成了两个,事半功倍呵。
>>> cooked1('value3')
foo called with cooked: cooked_value1, standard: value3
>>> cooked1('value4')
foo called with cooked: cooked_value1, standard: value4
>>> cooked2('value5')
foo called with cooked: cooked_value2, standard: value5
>>> cooked2('value6')
foo called with cooked: cooked_value2, standard: value6
如法炮制,可由原函数生成任意多个调制函数。
做出函数调用顺序图
用同样的调制技术,对调制出的函数,再次进行调制,可以产生下一级调制函数,......,由此逐步形成函数调用顺序图:
>>> def bar(child_fun, a):
... print "bar called with:", a
... return child_fun(a)
注意,函数 bar 的第一参数是个引用,即函数名。用这个办法,可以调制任何参数:
(其中的 float 和 min 是 Python 的内建函数)
>>> bar_f
相关文档:
原文地址 http://www.javaeye.com/wiki/Python/1371-python-graphics-library-pil-python-image-library-introduction
关于PIL库的一些概念
pil能处理的图片
类型
pil可以处理光栅图片(像素数据组成的的块)。
通道
一个图片可以包含一到多个数据通道,如果这些通道具有相同的维数和深度,Pil允许将这些通道进行叠加 ......
今天试验使用python连接 sql server 服务器。我记得以前使用ado连接access非常顺利,但是今天使用ado连接sql server竟然不成功。在python里面的出错信息都显示为转移序列,费了半天劲才搞明白:无效的类别字符串。
是连接字符串吗?测试了好几个 确认无误的数据库连接字符串,也是如此 。上网搜索,是有可能是 com的类别字 ......
1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()&n ......
不多说了,直接看代码吧!
import os
path = 'e:/Download/'
kzm = []
kzmTemp = set()
kzmTemp2 = []
dict = {}
for root,dirs,files in os.walk(path):
for file in files:
ext = os.path.splitext(file)[1][1:]
  ......
第一步:搭建手机运行平台
要在S60手机上运行PY开发的软件,首先就要搭建手机PY运行环境.诺基亚手机本身不支持Python,所以要安装Python插件.
PS:一定要安装在C盘!我一开始装E,结果出现了很严重的问题!不过,最近网上发现有E盘版的啦,你可以自己试验一下,哈哈
PythonScriptShell_1_4_5_3rdEd.SIS
Pyth ......