URN Logo
UNIX Resources » Linux » China Linux Forum » Python ±à ³Ì » µÚ10Ò³ » Q:¹ØÓÚUserDictµÄ__Init__·½·¨
announcement ÉùÃ÷: ±¾Ò³ÄÚÈÝΪÖйúLinuxÂÛ̳µÄÄÚÈݾµÏñ£¬ÎÄÕµİæÈ¨ÒÔ¼°ÆäËûËùÓеÄÏà¹ØÈ¨ÀûÊôÓÚÖйúLinuxÂÛ̳ºÍÏàÓ¦ÎÄÕµÄ×÷Õߣ¬Èç¹û×ªÔØ£¬Çë×¢Ã÷ÎÄÕÂÀ´Ô´¼°Ïà¹Ø°æÈ¨ÐÅÏ¢¡£
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  Òµ½çÐÂÎÅÓëÆÀÂÛ
  ×ÔÓÉÈí¼þÔÓ̸
  IT ÈËÉú
  LinuxÈí¼þ¿ìµÝ
  ·­Òë×÷·»
  LinuxͼÊéÓëÆÀÂÛ
  GNU Emacs/XEmacs
  Linux ÖÐÎÄ»·¾³ºÍÖÐÎÄ»¯
  Linux×ÀÃæÓë°ì¹«Èí¼þ
  Linux ¶àýÌåÓëÓéÀÖ°æ
  ×ÔÓÉÖ®´°Mozilla
  ±Ê¼Ç±¾µçÄÔÉϵÄLinux
  Gentoo
  Debian Ò»×å
  ÍøÂç¹ÜÀí¼¼Êõ
  Linux °²×°ÓëÈëÃÅ
  WEB·þÎñÆ÷ºÍFTP·þÎñÆ÷
  ÓòÃû·þÎñÆ÷ºÍÓʼþ·þÎñÆ÷
  Linux·À»ðǽºÍ´úÀí·þÎñÆ÷Ó¦ÓÃ
  Îļþ¼°´òÓ¡·þÎñÆ÷
  ¼¼ÊõÅàѵÓëÈÏÖ¤
  LinuxÄں˼¼Êõ
  Linux ǶÈë¼¼Êõ
  LinuxÉ豸Çý¶¯³ÌÐò
  Linux ¼¯Èº¼¼Êõ
  LINUXƽ̨Êý¾Ý¿â
  ÏµÍ³ºÍÍøÂ簲ȫ
  CPU Óë ±àÒëÆ÷
  ÏµÍ³¼ÆËãÑо¿ËùרÀ¸
  LinuxϵÄGUIÈí¼þ¿ª·¢
  C/C++±à³Ì°æ
  PHP ¼¼ Êõ
  Java&jsp¼¼Êõ
  Shell±à³Ì¼¼Êõ
  Perl ±à ³Ì
  Python ±à ³Ì
  XML/Web Service ¼¼Êõ
  ÓÀÔ¶µÄUnix
  FreeBSDÊÀ½ç
   
Q:¹ØÓÚUserDictµÄ__Init__·½·¨
Q:¹ØÓÚUserDictµÄ__Init__·½·¨ - blindbing [2005-04-10 00:57 | 498 byte(s)]
 
Re: Q:¹ØÓÚUserDictµÄ__Init__·½·¨ - blindbing [2005-04-10 01:20 | 777 byte(s)]
 
Subject: Q:¹ØÓÚUserDictµÄ__Init__·½·¨
Author: blindbing    Posted: 2005-04-10 00:57    Length: 498 byte(s)
[Original] [Print] [Top]
ÔÚdiveintopythonµÄÀý 3.7.ÖУº
UserDict __init__ ·½·¨

class UserDict:
def __init__(self, dict=None):
self.data = {}
if dict is not None:
¡¡¡¡¡¡¡¡¡¡self.update(dict)


±¾ÈËÓÞ±¿£¬×îºóÒ»ÐеÄд·¨×ÜÊÇÎÞ·¨Àí½â£¬¸öÈ˸оõÓ¦¸ÃÊÇself.data.update(dict)?ÄÇλ¸ßÈË¿ÉÒ
ÔÖ¸µãһϣ¿
лл¡­¡­
[Original] [Print] [Top]
Subject: Re: Q:¹ØÓÚUserDictµÄ__Init__·½·¨
Author: blindbing    Posted: 2005-04-10 01:20    Length: 777 byte(s)
[Original] [Print] [Top]
Ö»¹ËµÃ¿´DIVRINOTPYTHON,ÍüÁË¿´UserDict.py£¬ÔÚUserDict.pyÀï˵µÃºÜÇå³þÁË£¬µ÷ÓõÄÊÇUserDic
t±¾ÉíµÄupdate·½·¨¶ø²»ÊÇÖ±½Óµ÷ÓÃdataµÄupdate·½·¨¡­¡­


def update(self, dict=None, **kwargs):
if dict is None:
pass
elif isinstance(dict, UserDict):
self.data.update(dict.data)
elif isinstance(dict, type({})) or not hasattr(dict, 'items'):
self.data.update(dict)
else:
for k, v in dict.items():
self[k] = v
if len(kwargs):
self.data.update(kwargs)



³ÉÁË×ÔÎÊ×Ô´ðÌùÁË¡­¡­
[Original] [Print] [Top]
« Previous thread
Ë­°²×°¹ýpython 2¡£4 ºÍmysql 4¡£1 »¹ÓÐmysql £­python 1¡£2¡£0£¿Óеã
Python ±à ³Ì
µÚ10Ò³
Next thread »
½¨Òé:·¢ÌùÕßÏÈ̸̸ÈçºÎÈ¡µÃºÍ°²×°,²¢Æô¶¯³ÌÐò!
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
±¸°¸ÐòºÅ: ¾©ICP±¸05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:11:15, cost 0.040249109268188 ms.