Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

python ¶à¼Ì³Ð(2)

from:  http://www.chinesepython.org/pythonfoundry/tut2.3/tmp/multiple.html
9.5.1 ¶à¼Ì³Ð Multiple Inheritance
Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks as follows:
PythonͬÑùÓÐÏÞµÄÖ§³Ö¶à¼Ì³ÐÐÎʽ¡£¶à¼Ì³ÐµÄÀඨÒåÐÎÈçÏÂÀý£º
class DerivedClassName(Base1, Base2, Base3):
<statement-1>
.
.
.
<statement-N>
The only rule necessary to explain the semantics is the resolution rule used for class attribute references. This is depth-first, left-to-right. Thus, if an attribute is not found in DerivedClassName, it is searched in Base1, then (recursively) in the base classes of Base1, and only if it is not found there, it is searched in Base2, and so on.
ÕâÀïΨһÐèÒª½âÊ͵ÄÓïÒåÊǽâÎöÀàÊôÐԵĹæÔò¡£Ë³ÐòÊÇÉî¶ÈÓÅÏÈ£¬´Ó×óµ½ÓÒ¡£Òò´Ë£¬Èç¹ûÔÚ DerivedClassName £¨Ê¾ÀýÖеÄÅÉÉúÀࣩÖÐûÓÐÕÒµ½Ä³¸öÊôÐÔ£¬¾Í»áËÑË÷ Base1 £¬È»ºó£¨µÝ¹éµÄ£©ËÑË÷Æä»ùÀ࣬Èç¹û×îÖÕûÓÐÕÒµ½£¬¾ÍËÑË÷ Base2£¬ÒÔ´ËÀàÍÆ¡£
(To some people breadth first -- searching Base2 and Base3 before the base classes of Base1 -- looks more natural. However, this would require you to know whether a particular attribute of Base1 is actually defined in Base1 or in one of its base classes before you can figure out the consequences of a name conflict with an attribute of Base2. The depth-first rule makes no differences between direct and inherited attributes of Base1.)
£¨ÓÐЩÈËÈÏΪ¹ã¶ÈÓÅÏÈ£­£­ÔÚËÑË÷Base1µÄ»ùÀà֮ǰËÑË÷Base2ºÍBase3£­£­¿´ÆðÀ´¸üΪ×ÔÈ»¡£È»¶ø£¬Èç¹ûBase1ºÍBase2Ö®¼ä·¢ÉúÁËÃüÃû³åÍ»£¬ÄãÐèÒªÁ˽âÕâ¸öÊôÐÔÊǶ¨ÒåÓÚBase1»¹ÊÇBase1µÄ»ùÀàÖС£¶øÉî¶ÈÓÅÏȲ»Çø·ÖÊôÐԼ̳Ð×Ô»ùÀ໹ÊÇÖ±½Ó¶¨Òå¡££©
It is clear that indiscriminate use of multiple inheritance is a maintenance nightmare, given the reliance in Python on conventions to avoid accidental name conflicts. A well-known problem with multiple inheritance is a class derived from two classes that happen to have a common base class. While it is easy enough to figure out what happens i


Ïà¹ØÎĵµ£º

python ´´Ê¼ÈË·Ã̸¼1£º¹ØÓÚ django ºÍ ruby ÊÕ²Ø

python ´´Ê¼ÈË·Ã̸¼1£º¹ØÓÚ django ºÍ ruby ÊÕ²Ø
Ö÷³ÖÈË: Chris DiBona £¨Google ¿ªÔ´ÍøÕ¾¸ºÔðÈË£© and Leo Laporte £¨Twit ÍøÕ¾´´Ê¼ÈË£©
±»²É·ÃÈË£ºGuido van Rossum £¨python ´´Ê¼ÈË£©
Leo £º Python ȱÉÙһЩ±¾µØµÄ gui ¿â°É£¬Ö»ÓÐ tk ʲôµÄ£¬ Äã¾õµÃÕâÊDz»ÊÇÒ»¸öÎÊÌâÄØ£¿
Guido£º ÏÖÔÚÕâÔ½À´Ô½²»³ÉΪһ¸öÎÊÌâÁË£ ......

[ת] ×î¼òµ¥µÄʹÓÃUDPͨÐŵÄPython SocketÀý×Ó

À´Ô´£ºhttp://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
¿Í»§¶Ë³ÌÐò´úÂ룺
# Client program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM) ......

PythonÊý¾Ý½á¹¹Ö®——list

     PythonÖÐÓÐËÄÖÖÄÚ½¨µÄÊý¾Ý½á¹¹£ºList£¬Tuple£¬Dictionary£¬Set¡£±¾ÎÄÖ÷Òª½éÉÜList¡£
     ListÊÇÓÃÀ´´æ·ÅÒ»×é¶ÔÏóÐòÁС£¿ÉÒÔÏñlistÖÐÌí¼ÓÔªËØ¡¢É¾³ýÔªËØ£¬Í¬Ê±Ò²¿ÉÒÔÏñ·ÃÎÊÊý×éÒ»Ñù·ÃÎÊlist¡£ListÊǿɱäµÄÊý¾ÝÀàÐÍ¡£
    ÏÂÃæ£¬¸ø³öÒ»×élistµÄÊ¹Ó ......

PythonÏ̱߳à³Ì£¨Èý£©Í¬²½¶ÓÁÐ

ÎÒÃǾ­³£»á²ÉÓÃÉú²úÕß/Ïû·ÑÕß¹ØÏµµÄÁ½¸öÏß³ÌÀ´´¦ÀíÒ»¸ö¹²Ïí»º³åÇøµÄÊý¾Ý¡£ÀýÈçÒ»¸öÉú²úÕßÏ߳̽ÓÊÜÓû§Êý¾Ý·ÅÈëÒ»¸ö¹²Ïí»º³åÇøÀµÈ´ýÒ»¸öÏû·ÑÕßÏ̶߳ÔÊý¾ÝÈ¡³ö´¦Àí¡£µ«ÊÇÈç¹û»º³åÇøµÄ̫С¶øÉú²úÕߺÍÏû·ÑÕßÁ½¸öÒì²½Ï̵߳ÄËٶȲ»Í¬Ê±£¬ÈÝÒ׳öÏÖÒ»¸öÏ̵߳ȴýÁíÒ»¸öÇé¿ö¡£ÎªÁ˾¡¿ÉÄܵÄËõ¶Ì¹²Ïí×ÊÔ´²¢ÒÔÏàͬËٶȹ¤×÷µÄ¸÷Ï̵߳ĵ ......

python ¶à¼Ì³Ð

 from: http://www.cnblogs.com/dahuzizyd/archive/2005/03/01/111006.html
pythonÖ§³ÖÃæÏò¶ÔÏóµÄ±à³Ì·ç¸ñ£¬ÕâÀïÖ÷Ҫ˵˵pythonÖеĶà¼Ì³Ð£º
ÏÂÃæµÄ´úÂëʹÓÃpython2.4£¬°²×°ºóʹÓÃidleµÄIDE¿ª·¢»·¾³£¨ËµÊÇIDE £¬±ÈÆðdelphi,VS.netµÈ¼òµ¥µÃÌ«¶àÁË)
´ÓFile-New²Ëµ¥½¨Á¢Ò»¸ö.pyÎļþ£¬Ð´ÏÂÃæµÄ´úÂ룺
class SuperCl ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ