¹ØÓÚ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µÄlibĿ¼ÀïÓÐÒ»¸ö£ºthis.py£¬ËüÆäʵÊÇÒþ²Ø×ÅÒ»Ê×Ê«£¬Ô´ÂëÈçÏ£º
s =
"""Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......
ÒÔǰûÓÐд¹ýpython½Å±¾£¬ÓÚÊÇÕÒÁËÒ»¸ö¼òÒ׵Ľ̳̹ýÁËÒ»±éÓÚÊǾÍÊǸÉÁË¡£
ÕâÁ½Ìì²âÊÔmysql archiveÒýÇæµÄÐÔÄÜ£¬ÓÚÊÇÓÃpythonÏòarchive±íÖвåÈë10ÒÚÌõÊý¾Ý£¬python´óÖÂÊÇÈçÏÂдµÄ£º
for i in range(0,100000000)
insert into ....
½á¹ûÖ´ÐÐÖ®ºóϵͳ¾ÍËÀ»úÁË£¬ÇóÖú“ΰ¸ç”£¬×îºó·¢ÏÖÔÙÖ´Ðнű¾µÄʱºò£¬for in ......
PythonÖÐÖ´ÐÐϵͳÃüÁî³£¼û·½·¨ÓÐÁ½ÖÖ£º
Á½Õß¾ùÐè import os
(1) os.system
# ½ö½öÔÚÒ»¸ö×ÓÖÕ¶ËÔËÐÐϵͳÃüÁ¶ø²»ÄÜ»ñÈ¡ÃüÁîÖ´ÐкóµÄ·µ»ØÐÅÏ¢
system(command) -> exit_status
Execute the command (a string) in a subshell.
# Èç¹ûÔÙÃüÁîÐÐÏÂÖ´ÐУ¬½á¹ûÖ±½Ó´òÓ¡³öÀ´
>>> os. ......
Òª´´½¨ÄãµÄapp£¨½«djangoÅäÖõ½»·¾³±äÁ¿Ï£©
python manage.py startapp polls
ËüÃǽ«»á´´½¨Ò»¸öpollsÎļþ¼Ð£¬ÀïÃæµÄÄÚÈÝÊÇ£º
¡¡¡¡polls/
¡¡¡¡¡¡¡¡__init__.py
¡¡¡¡¡¡¡¡models.py
¡¡¡¡¡¡¡¡views.py
Õâ¸öĿ¼½á¹¹¾ÍÊÇappÓ¦ÓóÌÐò¡£
±àдÊý¾Ý¿âWebÓ¦ÓóÌÐòµÄµÚÒ»²½ÊǶ¨ÒåÄãµÄÄ£ÐͲ㗗»ù±¾ÉϾÍÊÇÄãµÄÊý¾Ý¿ ......
Ïà±È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 ......