摘要: 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 践道者 阅读(826) 评论(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 践道者 阅读(205) 评论(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 践道者 阅读(10615) 评论(1) 推荐(0) 编辑