随笔分类 -  python

摘要:1 import inspect2 3 def get_current_function_name():4 return inspect.stack()[1][3] 阅读全文
posted @ 2012-11-16 19:07 践道者 阅读(1055) 评论(0) 推荐(0)
摘要:非常简单,首先是在本机安装memcache服务并启动,d:\memcached\memcached.exe -d install #安装d:\memcached\memcached.exe -d start #启动如果没有在启动时配置参数,默认端口则为11211接着下载 memcache python版client#coding=utf8import memcachemcache= memcache.Client(['127.0.0.1:11211'])print mcache.set('say','hello,memcache') #displ 阅读全文
posted @ 2012-11-16 00:40 践道者 阅读(6545) 评论(0) 推荐(0)
摘要:由于python 没有抽象类、接口的概念,所以要实现这种功能得abc.py 这个类库,具体方式如下 1 from abc import ABCMeta, abstractmethod 2 3 #抽象类 4 class Headers(object): 5 __metaclass__ = ABCMeta 6 7 def __init__(self): 8 self.headers = '' 9 10 @abstractmethod11 def _getBaiduHeaders(self):pass12 13 def __str__(se... 阅读全文
posted @ 2012-11-15 19:25 践道者 阅读(34179) 评论(0) 推荐(1)
摘要:ord()把ASCII转换成数字chr()则相反,把数字转换成ASCIIord('s') #115chr(115) #s 阅读全文
posted @ 2012-11-15 09:32 践道者 阅读(4714) 评论(0) 推荐(0)
摘要:1 _DEFAULT_CONFIG = { 2 'name':None 3 } 4 5 class TestProperty(object): 6 def __init__(self, config): 7 self._config = config or {} 8 9 def __GetName(self):10 return self._config['name']11 12 def __SetName(self, name):13 self._config['name'] = name14 15... 阅读全文
posted @ 2012-11-14 10:12 践道者 阅读(740) 评论(0) 推荐(0)
摘要:在查看谷歌API类时发现这个函数,发现有问题,先上原函数: 1 def ValidateTypes(vars_tpl): 2 """Checks that each variable in a set of variables is the correct type. 3 4 Args: 5 vars_tpl: A tuple containing a set of variables to check. 6 7 Raises: 8 ValidationError: The given object was not one of the given accept. 阅读全文
posted @ 2012-11-13 17:59 践道者 阅读(2072) 评论(0) 推荐(0)
摘要:class TestStrRepr(object): def __str__(self): return "good, this is TestStr" #必须返回字符串 print TestStr() #good, this is TestStr可以认为__str__的目的是为print 这样的打印函数调用而设计的,当print 一个对象时,会自动调用其__str__方法而repr 函数则是将对象转换为字符串显示a = "hello"repr(a) # "'hello'"repr([1,2,3]) #'[1, 阅读全文
posted @ 2012-11-12 16:07 践道者 阅读(838) 评论(0) 推荐(0)
摘要:PI = 3.14 class Circ(object): def __init__(self): pass def __call__(self, r): return r * r * PI c = Circ() print c(2) #12.56 把对象当作函数来用,相当于重载括号运算符 阅读全文
posted @ 2012-11-12 14:39 践道者 阅读(218) 评论(0) 推荐(0)
摘要:针对谷歌API开发相应SEM工具过程中adwords API python版本的这句话,觉得好奇,研究了一下,由于sys.path是全局搜索路列表list,list具有insert方法,原型是insert(i, x)i表示位置x表示数据意思是把数据x插入到位置i中os.path.join('..', '..', '..', '..') 等于 http://www.cnblogs.com/http://www.cnblogs.com/../即把http://www.cnblogs.com/http://www.cnblogs.com 阅读全文
posted @ 2012-11-12 10:26 践道者 阅读(10663) 评论(1) 推荐(0)
摘要:很简单,第一个参数接收一个函数名,第二个参数接收一个可迭代对象 ls = [1,2,3] rs = map(str, ls) #打印结果 ['1', '2', '3'] lt = [1, 2, 3, 4, 5, 6] def add(num): return num + 1 rs = map(add, lt) print rs #[2,3,4,5,6,7] 阅读全文
posted @ 2012-10-29 14:27 践道者 阅读(61765) 评论(1) 推荐(2)