Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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Óï·¨

    pythonÌṩÁËÓÐÐò(sequence)ÀàÐÍ£¨×Ö·û´®£¬Ôª×飬ÁÐ±í¶¼ÊÇÓÐÐòÀàÐÍ£©£¬²¢ÇÒÌṩÁËÌØÊâµÄÓï·¨À´·½±ã¶ÔÕâЩÀàÐͽøÐвÙ×÷£¬×î³£ÓõÄÓÐÇÐÆ¬²Ù×÷¡£Í¬Ò»ÓÐÐòÀàÐ͵ĶÔÏóÖ®¼äÖ§³Ö¡±+¡±²Ù×÷·û£¬ÓÃÀ´Á¬³ÉÒ»¸öеÄÓÐÐò¶ÔÏó£¬ÓÐÐò¶ÔÏóÒ²¿ÉÒÔÓëÒ»¸öÕûÊý½øÐÐÏà³Ë£¬µÃµ½Ò»¸öеÄÓÐÐò¶ÔÏó¡£ÔÚµ÷ÊÔµÄʱºò£¬ÎÒ¾­³£Ê¹ÓÃÕâÑù ......

ѧϰ¡¶PythonÓïÑÔÈëÃÅ¡·µÚʮտò¼ÜÓëÓ¦ÓÃ

¹ØÓÚ¿ò¼Ü£¬Ö®Ç°ÌýµÃ±È½Ï¶à£¬ÌرðÊÇÔÚCPyGµÄÓʼþÁбíÉÏ£¬²»¹ý»¹Ã»ÓнӴ¥¹ý¡£
ÕâÒ»ÕÂÎÒ´òËãÂÔ¶Á£¬¼ÓÉÏÕâÁ½ÌìÉíÌå²»ÊÊ£¬¶ÁµÃ¸ü¼ÓÂÔÁË¡£
ÕâÒ»ÕÂÌáµ½µÄ¼¸¸ö¿ò¼ÜÎÒÌý˵µÄÓÐTKinterºÍSWIG¡£SWIG¸ãÁËһϣ¬TKinter¿´È˼ÒÓùý£¬×Ô¼º»¹Ã»ÓÐÓùý¡£¶ÔÕâЩ¿ò¼ÜİÉúµÃºÜ¡£ÒÔºóÅöÉÏÒªÓÃÁËÔÙÈÏÕæÑ§Ñ§¡£
µ½ÏÖÔÚ£¬¶ÔPythonËãÊÇÓÐЩÁ˽âÁË¡£ ......

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 ......

PythonǶÈëC++

PythonǶÈëC++Ïê½â(1)--HelloWorld
À´CSDNµÄʱºò£¬¸Õ¸Õ½Ó´¥Python£¬ÄÇʱºò¶ÔPythonµÄǶÈ벿·ÖºÜ¸ÐÐËȤ£¬Ö»ÊÇһֱûÓÐʱ¼äÀ´ÅªÇåÆäÃæÉ´£¬Òò´ËҲһֱûÓÐʹÓÃǶÈëµÄ¹¦ÄÜ£¬ÁíÒ»¸öÔ­ÒòÊÇÎÒ»¹Ã»ÓÐÕæÕýÓÃPythonд¹ýÒ»¸öÕýʽµÄÓÐÓõãµÄ¶«Î÷£¬²»¹ý£¬ÏÖÔڻعýÍ·À´¼ÌÐø¿´ÕâÒ»²¿·Ö£¬·¢ÏÖ»¹ÊÇͦ¼òµ¥µÄ¡£ÒÔǰÏë°ÑÕⲿ·Ö·­Òë³öÀ´£¬¿ÉÊÇÓ ......

Installing Python °²×°Python


   
You are here: Home ‣ Dive Into Python 3 ‣
Difficulty level: ♦♢♢♢♢
Installing Python °²×°Python
❝ Tempora mutantur nos et mutamur in illis. (Times change, and we change with them.) ❞
— ancient Roman proverb
 
D ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ