V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  ilucio  ›  全部回复第 3 页 / 共 3 页
回复总数  45
1  2  3  
2018 年 5 月 19 日
回复了 ilucio 创建的主题 Python 求问 Python 单例模式__new__函数执行顺序
我的是 2.7 环境,会输出 B
2018 年 5 月 17 日
回复了 wvc 创建的主题 程序员 推荐几本教为人处世学做人的书吧……
蛮欣赏楼主这种性格的人。叔本华说不要过早的学会圆滑与世故,否则容易走向平庸。
消费者那里的代码要改一下:
while True:
if self.w.empty():
pass
else:
info = self.w.get()
if info is not None:
do something
生产者生产完了后给消费者发送一个 None,然后消费者者会退出执行了
感觉问的应该是类的知识。在类里定义一个方法,会在堆上开辟内存生成一个函数对象,并把这个对象名放在类的__dict__中。

class apple(object):

def price (self):
print '2'

def weight (self):
print '400g'

print apple.__dict__

{'__module__': '__main__', 'weight': <function weight at 0x03868DB0>, 'price': <function price at 0x03868D70>, '__dict__': <attribute '__dict__' of 'apple' objects>, '__weakref__': <attribute '__weakref__' of 'apple' objects>, '__doc__': None}

可见方法 price 和 weight 分别在堆上的不同位置。
1  2  3  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   899 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 20:02 · PVG 04:02 · LAX 13:02 · JFK 16:02
♥ Do have faith in what you're doing.