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ËÆºõºÜÌÖÑáÐÞÊηû£¬Ã»Óг£¼ûµÄstaticÓï·¨¡£Æä¾²Ì¬·½·¨µÄʵÏÖ´óÖÂÓÐÒÔÏÂÁ½ÖÖ·½·¨£º
µÚÒ»ÖÖ·½Ê½£¨staticmethod£©£º
>>> class Foo:
str = "I'm a static method."
def ba ......
from http://blog.alexa-pro.cn/?p=189
1: os.listdir(path) //pathΪĿ¼
¹¦ÄÜÏ൱ÓÚÔÚpathĿ¼ÏÂÖ´ÐÐdirÃüÁ·µ»ØÎªlistÀàÐÍ
print os.listdir('..')
Êä³ö£º
[a,b,c,d]
2: os.path.walk(path,visit,arg)
path £ºÊǽ«Òª±éÀúµÄĿ¼
visit £ºÊÇÒ»¸öº¯ÊýÖ¸Õ룬º¯ÊýÔ²ÐÎΪ£º
callback(arg,dir,fileList)
ÆäÖÐargΪΠ......
ÏÂÃæ¶ÔPython½ø³Ì½øÐÐÉîÈë¶ø×ÐϸµÄѧϰ£¬Ê×ÏÈÏÈÈôó¼ÒÁ˽âÏÂʲôÊÇPython½ø³Ì£¬ÒÔ¼°ÔÚ¶ÔPython½ø³Ì½øÐд¦ÀíʱעÒâµÄÏà¹ØÎÊÌ⣬½ÓÏÂÀ´£¬¾ÍÓÉÎÒ¸ø´ó¼Ò½øÐнéÉÜѧϰ£¬½ö¹©´ó¼Òѧϰ¡£
²»¹ý£¬ËäÈ»½ø³Ì¿ÉÔÚµ¥¶ÀµÄÄÚ´æ¿Õ¼äÖÐÖ´ÐУ¬µ«³ý·ÇÕâЩPython½ø³ÌÔÚµ¥¶ÀµÄ´¦ÀíÆ÷ÉÏÖ´ÐУ¬·ñÔò£¬Êµ¼Ê²¢²»ÊǓͬʱ”ÔËÐеġ£ÊÇÓɲÙ×÷ ......
ãÂã¶®¶®µÄ°²×°ÁËPython£¬²»Îª±ðµÄ£¬Ö»Îª¸Ïµãʱ÷Ö£¬ÒòΪ¿´¼ûºÜ¶àÓÎÏ·¹«Ë¾¶¼ÒªÇó»áÒ»µãPython»òÕßLUA£¬Ã»°ì·¨£¬»¹ÊǶàѧһµãºÃ£¬·´ÕýÏÐ×ÅÒ²ÊÇÏÐ×Å¡£×Ô¼ºÄ¿Ç°²»¶®LINUX£¬ËùÒÔÔÝÇÒÓÃÓÃWINDOWSϵİɡ£
ÈëÃÅ»¹ºÃÈëÊÖ£¬²»ÊǾÞÄÑ£¬Ö¸³ö¼¸µãÓÐÒâ˼µÄ£º
ûÓлù±¾ÀàÐÍÁË£¬µ±ÎÒ°²cÓïÑÔÓ﷨дint xÊ ......
ÍøÂç³ô³æÒà¼´ÍøÂçÐű꣬ÊÇͨ¹ýijÖÖÊÖ¶ÎÒþʽ»ñÈ¡ÐÅÏ¢µÄµÄ·½·¨¡£
ÔÚbottle frameworkÖпÉÓÃÏÂÃæµÄ·½·¨ÊµÏÖ£º
Ê×ÏÈÔÚÄãÒªÓû§ä¯ÀÀÆ÷ÏÔʾµÄÒ³ÃætplÉÏǶÈëÒ»¸ö1*1ÏñËØµÄͼƬ£¬»ò¸üС¡£
Õâ¸öͼƬµØÖ·Ö¸ÏòÄã·þÎñÆ÷ÉÏij¸öÌØ¶¨Î»Öã¬Èçstatic/webtrack.png¡£
Óû§´ò¿ªÍøÒ³£¬¾Í»á·ÃÎÊÕâ¸öͼƬ£¨Í¨¹ýä¯ÀÀÆ÷Èçhttp://abc.abc.com/st ......