2007年11月23日 星期五 16:22
ÎÒÖ÷ÒªÊÇÏëÖªµÀÁ½¸ö instance µÄ·½·¨ÊDz»ÊÇ»áÕ¼ÓÃÁ½·ÝÄÚ´æ¡£Èç¹ûÊÇ£¬ÄÇÈç¹ûÎÒ ÎªÒ»¸ö class ´´½¨´óÁ¿ instance£¬ÄÇÆñ²»ÊÇÒªÕ¼¾Ý´óÁ¿Äڴ棿 On Nov 23, 2007 4:10 PM, limodou <limodou在gmail.com> wrote: > On Nov 23, 2007 4:06 PM, Roc Zhou <chowroc.z+l在gmail.com> wrote: > > This is the result comes from the Linux. > > > > And the result from Windows is: > > > > >>> class Test: > > var = 1 > > def func(self): pass > > >>> x = Test() > > >>> y = Test() > > >>> x.var is y.var > > True > > >>> x.func is y.func > > False > > >>> id(x.var) > > 11228488 > > >>> id(y.var) > > 11228488 > > >>> id(x.func) > > 14430976 > > >>> id(y.func) > > 14433656 > > > ¹À¼ÆÖ»ÄÜ¿´Ô´ÂëÈ¥ÁË¡£²»¹ÜÔõôÑù±È½Ï±äÁ¿µÄ½á¹ûÊÇÔ¤Æڵģ¬¶ø±È½ÏÁ½¸ö·½·¨ËƺõÊÇÓô¦²»´ó¡£ > > -- > I like python! > UliPad <>: http://code.google.com/p/ulipad/ > meide <>: http://code.google.com/p/meide/ > My Blog: http://www.donews.net/limodou > -- ------------------------------------------------------------------------ My Projects: http://sourceforge.net/projects/crablfs http://www.yourlfs.org/ http://www.yourlfs.org/#ru_data_man http://www.yourlfs.org/tree.html http://www.yourlfs.org/sysadm_zh_CN.html My Blog: http://chowroc.blogspot.com/ Looking for a space and platform to exert my originalities (for my projects)... -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071123/f00a29dc/attachment.html
2007年11月23日 星期五 16:27
ºÃÏñÊǵġ£¡£PythonûÓÐstatic functionһ˵ On 11/23/07, Roc Zhou <chowroc.z+l在gmail.com> wrote: > > ÎÒÖ÷ÒªÊÇÏëÖªµÀÁ½¸ö instance µÄ·½·¨ÊDz»ÊÇ»áÕ¼ÓÃÁ½·ÝÄÚ´æ¡£Èç¹ûÊÇ£¬ÄÇÈç¹ûÎÒ > Ϊһ¸ö class ´´½¨´óÁ¿ instance£¬ÄÇÆñ²»ÊÇÒªÕ¼¾Ý´óÁ¿Äڴ棿 > > On Nov 23, 2007 4:10 PM, limodou <limodou在gmail.com> wrote: > > > On Nov 23, 2007 4:06 PM, Roc Zhou < chowroc.z+l在gmail.com> wrote: > > > This is the result comes from the Linux. > > > > > > And the result from Windows is: > > > > > > >>> class Test: > > > var = 1 > > > def func(self): pass > > > >>> x = Test() > > > >>> y = Test() > > > >>> x.var is y.var > > > True > > > >>> x.func is y.func > > > False > > > >>> id(x.var) > > > 11228488 > > > >>> id( y.var) > > > 11228488 > > > >>> id(x.func) > > > 14430976 > > > >>> id(y.func) > > > 14433656 > > > > > ¹À¼ÆÖ»ÄÜ¿´Ô´ÂëÈ¥ÁË¡£²»¹ÜÔõôÑù±È½Ï±äÁ¿µÄ½á¹ûÊÇÔ¤Æڵģ¬¶ø±È½ÏÁ½¸ö·½·¨ËƺõÊÇÓô¦²»´ó¡£ > > > > -- > > I like python! > > UliPad <>: http://code.google.com/p/ulipad/ > > meide <>: http://code.google.com/p/meide/ > > My Blog: http://www.donews.net/limodou > > > > > > -- > ------------------------------------------------------------------------ > My Projects: > http://sourceforge.net/projects/crablfs > http://www.yourlfs.org/ > http://www.yourlfs.org/#ru_data_man > http://www.yourlfs.org/tree.html > http://www.yourlfs.org/sysadm_zh_CN.html > My Blog: > http://chowroc.blogspot.com/ > Looking for a space and platform to exert my originalities (for my > projects)... > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071123/e879ec09/attachment.htm
2007年11月23日 星期五 16:38
On Nov 23, 2007 4:22 PM, Roc Zhou <chowroc.z+l at gmail.com> wrote: > 我主要是想知道两个 instance 的方法是不是会占用两份内存。如果是,那如果我 > 为一个 class 创建大量 instance,那岂不是要占据大量内存? > Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def f(): ... pass ... >>> a = A() >>> b = A() >>> dir(a.f) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func', 'im_self'] >>> id(a.f.im_func) 2146512820 >>> id(b.f.im_func) 2146512820 >>> id(b.f.im_class) 2146527772 >>> id(a.f.im_class) 2146527772 >>> id(a.f.im_self) 2146570860 >>> id(b.f.im_self) 2146570764 >>> id(b) 2146570764 >>> id(a) 2146570860 两个 f 的 im_self 不一样, 其实 im_self 就是 拥有它们的对象
2007年11月23日 星期五 16:56
Ã÷°×ÁË¡£ лл '') On Nov 23, 2007 4:38 PM, lubiao <lubiao.py在gmail.com> wrote: > On Nov 23, 2007 4:22 PM, Roc Zhou <chowroc.z+l在gmail.com> wrote: > > ÎÒÖ÷ÒªÊÇÏëÖªµÀÁ½¸ö instance µÄ·½·¨ÊDz»ÊÇ»áÕ¼ÓÃÁ½·ÝÄÚ´æ¡£Èç¹ûÊÇ£¬ÄÇÈç¹ûÎÒ > > Ϊһ¸ö class ´´½¨´óÁ¿ instance£¬ÄÇÆñ²»ÊÇÒªÕ¼¾Ý´óÁ¿Äڴ棿 > > > Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) > [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>> class A: > ... def f(): > ... pass > ... > >>> a = A() > >>> b = A() > >>> dir(a.f) > ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', > '__get__', '__getattribute__', '__hash__', '__init__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', > 'im_class', 'im_func', 'im_self'] > >>> id(a.f.im_func) > 2146512820 > >>> id(b.f.im_func) > 2146512820 > >>> id(b.f.im_class) > 2146527772 > >>> id(a.f.im_class) > 2146527772 > >>> id(a.f.im_self) > 2146570860 > >>> id(b.f.im_self) > 2146570764 > >>> id(b) > 2146570764 > >>> id(a) > 2146570860 > > Á½¸ö f µÄ im_self ²»Ò»Ñù£¬ Æäʵ im_self ¾ÍÊÇ ÓµÓÐËüÃǵĶÔÏó > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- ------------------------------------------------------------------------ My Projects: http://sourceforge.net/projects/crablfs http://www.yourlfs.org/ http://www.yourlfs.org/#ru_data_man http://www.yourlfs.org/tree.html http://www.yourlfs.org/sysadm_zh_CN.html My Blog: http://chowroc.blogspot.com/ Looking for a space and platform to exert my originalities (for my projects)... -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071123/be8da155/attachment.html
Zeuux © 2025
京ICP备05028076号