Python MySqlDB Ôöɾ¸ÄÊý¾Ý¿â
ÏÂÔØ°²×°MySQLdb
http://sourceforge.net/projects/mysql-python/ ºÃÏñû¿´µ½windows°æ±¾for python2.6µÄÏÂÔØ£¬ÍøÉÏËÑË÷µ½Ò»¸ö
http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe
°²×°ºóimport MySQLdb»á³öÏÖ DeprecationWarning: the sets module is deprecated ÕâÑùÒ»¸ö¾¯¸æ£¬googleÖ®
ÔÒòÊÇ2.6²»ÖªsetsÕâ¸öÄ£¿é£¬²»¹ýÒѾÌí¼ÓÁËsetÄÚÖú¯Êý¡£ÕÒµ½MySQLdbÎļþ¼ÐµÄÖÐ__init__.py,×¢Ê͵ôfrom sets import ImmutableSet class DBAPISet(ImmutableSet):Ìí¼Óclass DBAPISet(frozenset):£»ÕÒµ½converters.py×¢Ê͵ôfrom sets import BaseSet, Set¡£È»ºóÐ޸ĵÚ45ÐкÍ129ÐÐÖеÄSetΪset¡£
¸ã¶¨¡£
ÏÂÃæ¿ªÊ¼²Ù×÷µÄdemo:
Python´úÂë
# -*- coding: utf-8 -*-
#mysqldb
import time, MySQLdb
#Á¬½Ó
conn=MySQLdb.connect(host="localhost",user="root",passwd="",db="test",charset="utf8")
cursor = conn.cursor()
#дÈë
sql = "insert into user(name,created) values(%s,%s)"
param = ("aaa",int(time.time()))
n = cursor.execute(sql,param)
print n
#¸üÐÂ
sql = "update user set name=%s where id=3"
param = ("bbb")
n = cursor.execute(sql,param)
print n
#²éѯ
n = cursor.execute("select * from user")
for row in cursor.fetchall():
for r in row:
print r
#ɾ³ý
sql = "delete from user where name=%s"
param =("aaa")
n =&nb
Ïà¹ØÎĵµ£º
ÁÐ±í·½·¨£º
·½·¨
˵Ã÷
append( item )
ÔÚÁбíĩβ²åÈ루item £©
count( element )
·µ»ØelementÔÚÁбíÖгöÏֵĴÎÊý
extend( newlist )
½«newlistµÄÔªËØ²åÈëÁбíĩβ
index( element )
·µ»ØelementÔÚÁбíÖеÄË÷Òý£¬Èç¹û²»´æÔÚ£¬ÔòÒý·¢ValueErrorÒì³£
insert( index , item )
ÔÚindex ......
Python±ê×¼¿â-randomÄ£¿é
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉú³ÉÆ÷. »ù±¾Ëæ»úÊýÉú³ÉÆ÷(»ùÓÚ Wichmann ºÍ Hill , 1982 µÄÊýѧÔËËãÀíÂÛ) ¿ÉÒÔͨ¹ýºÜ¶à·½·¨·ÃÎÊ, Èç Example 2-29 Ëùʾ. 2.17.0.1. Example 2-29. ʹÓà random Ä£¿é»ñµÃËæ»úÊý×Ö File: random-example-1.py import random for i i
¡¡¡¡
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉ ......
¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËØ¶¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vhe ......
DecoratorsÊÇpythonÖбȽÏÄÑÒÔÀí½âµÄ¶«Î÷£¬µ±È»Èç¹ûÄã½Ó´¥¹ýjavaµÄannotation£¬»á·¢ÏÖÕâ¸öDecoratorsÔÚÓï·¨ÉϷdz£µÄÏàËÆ£¬µ«ÊÇÁ½ÕßµÄÉè¼Æ¶¯»úȴûʲô¹²Í¬µã£»
ÕâÀï½²µÄpythonÖеÄdecoratorsÊǶÔpythonÖеÄfunction/method×ö×°ÊΣ¬ÕâЩÐÞÊνöÊǵ±ÉùÃ÷Ò»¸öº¯Êý»òÕß·½·¨µÄʱºò£¬²Å»áÓ¦ÓõĶîÍâµ÷Óá£
pythonÖеÄdecorator·Ö ......
ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
do_something()
else:
do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......