2013年8月25日
摘要: 本文环境:Python 2.7一个类的三个对象实例的属性被同时修改有段代码如下:class task_queue: queue=[] def append(self,obj): self.queue.append(obj) def print_queue(self): print self.queue if __name__=="__main__": a=task_queue() b=task_queue() c=task_queue() a.append('tc_1') ... 阅读全文
posted @ 2013-08-25 11:46 turtle_fly 阅读(62837) 评论(1) 推荐(2) 编辑
摘要: 本文环境:Python 2.7使用 print obj 而非 print(obj)一些背景sys.stdout 与 print当我们在 Python 中打印对象调用 print obj 时候,事实上是调用了 sys.stdout.write(obj+'\n')print 将你需要的内容打印到了控制台,然后追加了一个换行符print 会调用 sys.stdout 的 write 方法以下两行在事实上等价:sys.stdout.write('hello'+'\n')print 'hello'sys.stdin 与 raw_input当 阅读全文
posted @ 2013-08-25 10:45 turtle_fly 阅读(100856) 评论(2) 推荐(9) 编辑