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

python socket server ²¢·¢£¨×ª£©

import SocketServer, time, select, sys
from threading import Thread
COMMAND_HELLO = 1
COMMAND_QUIT = 2
# The SimpleRequestHandler class uses this to parse command lines.
class SimpleCommandProcessor:
    def __init__(self):
        pass
    def process(self, line, request):
        """Process a command"""
        args = line.split(' ')
        command = args[0].lower()
        args = args[1:]
        if command == 'hello':
            request.send('HELLO TO YOU TO!\n\r')
            return COMMAND_HELLO
        elif command == 'quit':
            request.send('OK, SEE YOU LATER\n\r')
            return COMMAND_QUIT
        else:
            request.send('Unknown command: "%s"\n\r' % command)
# SimpleServer extends the TCPServer, using the threading mix in
# to create a new thread for every request.
class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    # This means the main server will not do the equivalent of a
    # pthread_join() on the new threads. With this set, Ctrl-C will
    # kill the server reliably.
    daemon_threads = True
    # By setting this we allow the server to re-bind to the address by
    # setting SO_REUSEADDR, meaning you don't have to wait for
    # timeouts when you kill the server and the sockets don't get
 


Ïà¹ØÎĵµ£º

python hidden features

from http://stackoverflow.com/questions/101268/hidden-features-of-python
http://www.okpython.com/bbs/thread-3434-1-1.html
http://www.okpython.com/bbs/thread-3436-1-2.html
http://www.okpython.com/bbs/thread-3437-1-2.html
http://www.okpython.com/bbs/thread-3438-1-1.html
http://www.okpython.com/bb ......

python Ä£¿éµÄ__name__ __main__

ÿ¸öÄ£¿é¶¼ÓÐÒ»¸öÃû³Æ£¬ÔÚÄ£¿éÖпÉÒÔͨ¹ýÓï¾äÀ´ÕÒ³öÄ£¿éµÄÃû³Æ¡£ÕâÔÚÒ»¸ö³¡ºÏÌØ±ðÓÐÓÃ
——¾ÍÈçÇ°ÃæËùÌáµ½µÄ£¬µ±Ò»¸öÄ£¿é±»µÚÒ»´ÎÊäÈëµÄʱºò£¬Õâ¸öÄ£¿éµÄÖ÷¿é½«±»ÔËÐС£
ÿ¸öPythonÄ£¿é¶¼ÓÐËüµÄ__name__£¬Èç¹ûËüÊÇ'__main__'£¬Õâ˵Ã÷Õâ¸öÄ£¿é±»Óû§µ¥¶ÀÔËÐУ¬
ÎÒÃÇ¿ÉÒÔ½øÐÐÏàÓ¦µÄÇ¡µ±²Ù×÷¡£
#!/usr/bin/pytho ......

python 2.4Óë2.5ÖÐ×Ö·û´®Óëdatetimeת»»µÄÇø±ð

python 2.4ÖÐdatetimeÓÐstrftime·½·¨¶øÎÞstrptime·½·¨
¶øpython2.5ÖÐÕâÁ½¸ö·½·¨¾ùÓУ¬¶øÎҵĿª·¢»·¾³ÕýºÃÊÇpython 2.5£¬¶øÔËÐл·¾³ÔòÊÇpython 2.4
¿ª·¢»·¾³Ïµ÷ÊԺõijÌÐò£¬ÔÚ·þÎñÆ÷ÉϾͲ»run¡£²éÁËÒ»ÏÂpythonµÄ¹Ù·½Îĵµ
£¬Ð±Ìåд×Å£ºNew
in version 2.5.
²»¼æÈݵĴúÂëÈçÏ£º
PythonÓïÑÔ
:
test_strptime.py
res ......

Python continue

1.º¯Êý
º¯Êýͨ¹ýdef¹Ø¼ü×Ö¶¨Òå¡£def¹Ø¼ü×Öºó¸úÒ»¸öº¯ÊýµÄ ±êʶ·û
Ãû³Æ£¬È»ºó¸úÒ»¶ÔÔ²À¨ºÅ¡£Ô²À¨ºÅÖ®ÖпÉÒÔ°üÀ¨Ò»Ð©±äÁ¿Ãû£¬¸ÃÐÐÒÔðºÅ½áβ¡£½ÓÏÂÀ´ÊÇÒ»¿éÓï¾ä£¬ËüÃÇÊǺ¯ÊýÌå¡£º¯ÊýÒ²ÓÐÐβκÍʵ²Î£¬ÓëC++Ψһ²»Ò»ÑùµÄÊÇÐββ»Ð´ÀàÐͶøÒÑ£¬Ö±½Óд±äÁ¿Ãû¡£
2.globalÓï¾ä
Èç¹ûÄãÏëҪΪһ¸ö¶¨ÒåÔÚº¯ÊýÍâµÄ±äÁ¿¸³Öµ£¬ÄÇÃ´Ä ......

WebTrack ÔÚ python bottle frameworkÖеļòµ¥ÊµÏÖ

ÍøÂç³ô³æÒà¼´ÍøÂçÐű꣬ÊÇͨ¹ýijÖÖÊÖ¶ÎÒþʽ»ñÈ¡ÐÅÏ¢µÄµÄ·½·¨¡£
ÔÚbottle frameworkÖпÉÓÃÏÂÃæµÄ·½·¨ÊµÏÖ£º
Ê×ÏÈÔÚÄãÒªÓû§ä¯ÀÀÆ÷ÏÔʾµÄÒ³ÃætplÉÏǶÈëÒ»¸ö1*1ÏñËØµÄͼƬ£¬»ò¸üС¡£
Õâ¸öͼƬµØÖ·Ö¸ÏòÄã·þÎñÆ÷ÉÏij¸öÌØ¶¨Î»Öã¬Èçstatic/webtrack.png¡£
Óû§´ò¿ªÍøÒ³£¬¾Í»á·ÃÎÊÕâ¸öͼƬ£¨Í¨¹ýä¯ÀÀÆ÷Èçhttp://abc.abc.com/st ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ