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

¹ØÓÚPythonÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ

#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
    """Simple functor class."""
    def __init__( self, fn, *args ):
        self.fn = fn
        self.args = args
    def __call__( self, *args ):
        self.fn( *(self.args + args) )
#Ïë¶Ô¸Ãº¯Êý½øÐлص÷²Ù×÷       
def test_callback1(arg1, arg2):
    print "test_callback1", arg1, arg2
#ÏȽøÐмòµ¥µØ²âÊÔ
obj_call1 = Functor(test_callback1, 1111, 'qweqwe111111111')
obj_call1()
#½á¹û£º
#test_callback1 1111 qweqwe111111111
#¿´¿´¹ý³ÌÖдøÈë²ÎÊýµÄ·½Ê½
def test_callback2(arg1, arg2, call_arg):
    print "test_callback2", arg1, arg2, call_arg
obj_call2 = Functor(test_callback2, 2222, 'qweqwe22222222')
obj_call2(222)#¹ý³ÌÖÐÊäÈë²ÎÊý£¬²¢ÇÒʹ»Øµ÷º¯ÊýµÃµ½Õâ¸ö²ÎÊý
#½á¹û£º
#test_callback2 2222 qweqwe22222222 222
#ÔÙÀ´¿´¿´¶ÔÏóÖеķ½·¨±»ÓÃÀ´»Øµ÷
#»ù±¾Ô­ÀíÓëÉÏÃæÁ½¸öÀý×ÓÏàͬ£¬µ«¿ÉÒÔÒýÈë¶ÔÏó±¾ÉíµÄº¯Êý
#²¢ÇÒÒ²¿ÉÒýÈëÆäËû¶ÔÏó½øÐлص÷£¬ÄÇôËüµÄÓ÷¨½«»á·Ç³£·á¸»
class Test:
    def __init__(self):
        pass
   
    def test_callback1(self, arg1, arg2):
        print "Test.test_callback 1111", arg1, arg2
   
    def test_callback2(self, arg1, arg2, call_arg):
        print "Test.test_callback 2222", arg1, arg2, call_arg
       
    def test_callback_arg(self):
        obj_call1 = Functor(self.test_callback1, 1111, 'qweqwe1111')
        print "obj_call1 = ",obj_call1
     


Ïà¹ØÎĵµ£º

¶¯Ì¬ÓïÑÔÖ®ËÄ£ºPython¼ò½é


PythonÊÇĿǰ¹ã·ºÊ¹ÓõÄÒ»ÃŶ¯Ì¬ÓïÑÔ£¬ÀàËÆJava£¬Ô´´úÂë±ØÐëÊ×ÏÈÓɱàÒëÆ÷ת»»³É×Ö½ÚÂ루byte code£©£¬È»ºóÔÙÓɽâÊÍÆ÷À´Ö´ÐÐ×Ö½ÚÂë¡£ÓëJava²»Í¬µÄÊÇ£¬PythonµÄ±àÒëÆ÷ºÍ½âÊÍÆ÷¶¼ÊÇÒ»¸ö³ÌÐò¡£Òò´Ë£¬Ô´´úÂëÒ²¿ÉÒÔÖ±½Ó½»¸øÕâ¸ö±àÒëÆ÷£¯½âÊÍÆ÷À´Ö´ÐС£
ʹÓÃPython±àд³ÌÐò£¬Äã²»ÐèÒªÔ¤ÏÈÉùÃ÷ºÃ±äÁ¿µÄÀàÐÍ£¬ÒòΪPythonÖбäÁ¿µÄÀ ......

BeautifulSoup Python×¥ÍøÒ³Ð¡Àý×Ó

# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup, Tag
import re
page = urllib2.urlopen("http://bj.ganji.com/piao/zz_%E5%8C%97%E4%BA%AC-%E5%8D%97%E6%98%8C/20100210/")
soup = BeautifulSoup(page)
#ss = soup.findAll('a', href=re.compile(r"^/piao/100.&qu ......

PythonÎļþµÄ¶Áд

Ïà±Èjava¶øÑÔ£¬PythonÓü¸ÐдúÂë¾Í¿ÉÒÔ´úÌæjavaÊ®À´ÐеĴúÂë£¬ÕæµÄ·Ç³£²»´í
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
Îļþ´´½¨
#use readline() read file
f = o ......

pythonµÄ±Õ°ü(3.0֮ǰ¼°Ö®ºó)

Ê×ÏÈ, ˵˵pythonÀïÃæµÄ±Õ°ü°É:
1. ÐèÒªº¯ÊýǶÌ×, ¾ÍÊÇÒ»¸öº¯ÊýÀïÃæÔÙдһ¸öº¯Êý.
2. Íⲿº¯ÊýÐèÒª·µ»ØÒ»¸öÄÚ²¿º¯ÊýµÄÒýÓÃ
3. Íⲿº¯ÊýÖÐÓÐһЩ¾Ö²¿±äÁ¿, ²¢ÇÒ, ÕâЩ¾Ö²¿±äÁ¿ÔÚÄÚ²¿º¯ÊýÖÐÓÐʹÓÃ
¸ÅÄî:
1. ×ÔÓɱäÁ¿: Íⲿº¯ÊýÖж¨ÒåµÄ¾Ö²¿±äÁ¿, ²¢ÇÒÔÚÄÚ²¿º¯ÊýÖб»Ê¹ÓÃ.
2. ±Õ°ü: ÄǸöʹÓÃÁË×ÔÓɱäÁ¿²¢±»·µ»ØµÄÄÚ²¿º¯Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ