# 写好Python之函数## 避免使用可变对象作为参数德默认值当Python解释器对函数定义时,通过默认参数表达式来判断他们的值。该表达式仅发生一次。调用该函数不会触发其他的参数表达式值。由于计算的值用于所有函数调用序列,使用可变对象作为默认值会发生一些未期待的结果。可变对象意味值可以直接进行修改...
分类:
编程语言 时间:
2014-06-18 21:10:47
阅读次数:
206
比较中文是否相等:if str1.decode("GB2312").encode("utf-8") ==str2.decode("GB2312").encode("utf-8"): print "=="注: decode中时str1 str2使用的中文编码方式, encode统一用utf-8形式比....
分类:
编程语言 时间:
2014-06-18 19:26:41
阅读次数:
384
# 使用Cython为Python写扩展1:初识CythonCython使为Python写C扩展就如同写Python代码一样简单。广泛用于数学软件包,SAGE公司,作为执行快速,可扩展的运算。它提供了安全和可维护的方法通过自动生成所需代码来构建原生Python模块。我们经常会使用Cython将C/C...
分类:
编程语言 时间:
2014-06-18 17:48:59
阅读次数:
382
我们知道,一个典型的Map-Reduce过程包 括:Input->Map->Partition->Reduce->Output。Partition负责把Map任务输出的中间结果 按key分发给不同的Reduce任务进行处理。Hadoop 提供了一个很有用的partitioner类KeyFieldBa...
分类:
编程语言 时间:
2014-06-18 17:00:55
阅读次数:
332
如果在某个函数中包含了yield, 这意味着这个函数已经是一个Generator, 它的执行 会和其他普通的函数有很多不同。比如: def h(): print 'To be brave' yield 5 h()可以看到,调用h()之后,print语句并没有执行, 这就是yi...
分类:
编程语言 时间:
2014-06-18 16:40:47
阅读次数:
235
1- 多行注释 ''' ''' 或 """ """'''this is the standard way to include a multiple-line comment in you code'''"""this is the standard way to include a multipl...
分类:
编程语言 时间:
2014-06-18 15:46:56
阅读次数:
264
1、生成动态链接库[root@typhoeus79 c]# more head.c #include #include typedef struct _point{ int x; int y;}Point;Point * InitPoint(int x,int y){ Point ...
分类:
编程语言 时间:
2014-06-18 15:45:00
阅读次数:
267
升级了mac操作系统,安装python的python-ldap,报错Modules/LDAPObject.c:18:10:fatalerror:‘sasl.h‘filenotfound#include<sasl.h>^1errorgenerated.error:command‘cc‘failedwithexitstatus1----------------------------------------Cleaningup...Command/usr/bin/python..
分类:
编程语言 时间:
2014-06-16 16:21:35
阅读次数:
758