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

Python sqlite3ºÍµ¥Ôª²âÊÔ

 
import os
import unittest # °üº¬µ¥Ôª²âÊÔÄ£¿é
import sqlite3 as sqlite # °üº¬sqlite3Ä£¿é
def get_db_path():
return "sqlite_testdb"
class TransactionTests(unittest.TestCase): # µ¥Ôª²âÊÔµÚÒ»²½:¡¡ÓÉTestCaseÅÉÉúÀà
def setUp(self): # µ¥Ôª²âÊÔ»·¾³ÅäÖÃ
try:
os.remove(get_db_path())
except:
pass
self.con1 = sqlite.connect(get_db_path(), timeout=0.1) # Á¬½ÓÊý¾Ý¿â
self.cur1 = self.con1.cursor() # »ñÈ¡Óαê
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
self.cur2 = self.con2.cursor()
def tearDown(self): # µ¥Ôª²âÊÔ»·¾³Çå³ý
self.cur1.close() # ¹Ø±ÕÓαê
self.con1.close() # ¹Ø±ÕÁ¬½Ó
self.cur2.close()
self.con2.close()
os.unlink(get_db_path())
def CheckDMLdoesAutoCommitBefore(self):
self.cur1.execute("create table test(i)") # Ö´ÐÐSQL²éѯ
self.cur1.execute("insert into test(i) values (5)")
self.cur1.execute("create table test2(j)")
self.cur2.execute("select i from test")
res = self.cur2.fetchall()
self.failUnlessEqual(len(res), 1) # ²âÊÔ
def CheckInsertStartsTransaction(self):
self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)")
self.cur2.execute("select i from test")
res = self.cur2.fetchall()
self.failUnlessEqual(len(res), 0)
def CheckUpdateStartsTransaction(self):
self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)")
self.con1.commit()
self.cur1.execute("update test set i=6")
self.cur2.execute("select i from test")
res = self.cur2.fetchone()[0]
self.failUnlessEqual(res, 5)
def CheckDeleteStartsTransaction(self):
self.cur1.exec


Ïà¹ØÎĵµ£º

[_Êý¾ÝÍÚ¾ò_] pythonʵ¼ùÖ®1

 ¼Æ»®Õâ¸öÐÇÆÚѧϰÓÃpythonʵÏÖ¾ö²ßÊ÷Ëã·¨¡£½ñÍí¾ÍÅöµ½Á˺öàÎÊÌ⣬ºÃ¾ÃûÓÐÓÃpythonÁË£¬²¢ÇÒ3.0ºÍÊé±¾ÉϵÄÓÐЩ¶«Î÷²»Ì«Ò»Ö£¬ÕâÀï¼Ç¼Ï¼¸¸öµØ·½¡£
1£© import module Èç¹û²»ÊÇÔÚ±ê׼Ŀ¼Ï£¨ÏµÍ³µÄpath£¬pythonµÄĿ¼£¬µ±Ç°Ä¿Â¼£©£¬ÄÇôÐèÒªÏÈimport sys£¬È»ºósys.path.append('')£»
2£© ¸Ä±äÔ´Îļþºó£¬ÔÙ´Îimport ......

python pyc

 Ê²Ã´ÊÇpycÎļþ
pycÊÇÒ»ÖÖ¶þ½øÖÆÎļþ£¬ÊÇÓÉpyÎļþ¾­¹ý±àÒëºó£¬Éú³ÉµÄÎļþ£¬ÊÇÒ»ÖÖbyte code£¬pyÎļþ±ä³ÉpycÎļþºó£¬¼ÓÔصÄËÙ¶ÈÓÐËùÌá¸ß£¬¶øÇÒpycÊÇÒ»ÖÖ¿çƽ̨µÄ×Ö½ÚÂ룬ÊÇÓÉpythonµÄÐéÄâ»úÀ´Ö´Ðеģ¬Õâ¸öÊÇÀàËÆÓÚJAVA»òÕß.NETµÄÐéÄâ»úµÄ¸ÅÄî¡£pycµÄÄÚÈÝ£¬ÊǸúpythonµÄ°æ±¾Ïà¹ØµÄ£¬²»Í¬°æ±¾±àÒëºóµÄpycÎļþÊDz»Í¬µÄ£¬2 ......

Python¿ª·¢Activex×é¼þ

PythonÇ¿µÄ¹¦ÄܾÍÔÚÓÚËüÎÞËù²»ÄÜ¡£
ʹÓÃwin32comÄ£¿é¿ª·¢window ActiveXµÄʾÀý£º£¨Èç¹ûÄ㻹ûÓÐ×°win32comÄ£¿éµÄ»°£¬Çëµ½http://python.net/crew/skippy/win32/Downloads.htmlÏÂÔØ£©¡£
# SimpleCOMServer.py
class PythonUtilities:
_public_methods_ = ['SplitString']
_reg_progid_ = "Python.Utilities"
......

ʹÓÃPythonÓïÑÔÉè¼Æ»ùÓÚHTMLµÄCÓïÑÔÓï·¨¼ÓÁÁÏÔʾ³ÌÐò

2005-2006ѧÄêµÚ1ѧÆÚ
±à Òë Ô­ Àí 
¿Î ³Ì Éè ¼Æ ±¨ ¸æ
°à¼¶   02¼Æ(¶þ)   
ѧºÅ     19     
ÐÕÃû     ÁõÏþÃ÷     
³É¼¨           
Ö¸µ¼½Ìʦ   ¬³¯»Ô   
Ò»¡¢   Éè¼ÆÄ¿µÄ
¼ÓÉî¶Ô±àÒ ......

Python×°ÊÎÆ÷

Ô­ÎÄ£ºhttp://www.klipdas.com/blog/?p=python-decorator
python×°ÊÎÆ÷½éÉÜ
Python 2.2ÖÐÒýÈëµÄ classmethod() ºÍ staticmethod() ÄÚÖú¯Êý£¬Äã¿ÉÒÔÕâÑùµ÷ÓÃclassmethod()£º
class A:
def foo(self, y):
print y
foo = classmethod(foo)
Ò²¿ÉÒÔÕâÑù£º
class A:
@classmethod
def foo(sel ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ