易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

python安装之setuptools

David 在本文中将带领我们了解一下 setuptools 框架,它是 Python Enterprise Application Kit(PEAK)的一个副项目。 setuptools 替换了标准的 distutils 库,并为 Python 添加了版本化的包和依赖性管理。Perl 用户比较熟悉 CPAN,而 Ruby 用户则比较熟悉 Gems;引导 setuptools 的 ez_setup 工具和随之而生的扩展后的 eas ......

python 的函数Decorators

Decorators是python中比较难以理解的东西,当然如果你接触过java的annotation,会发现这个Decorators在语法上非常的相似,但是两者的设计动机却没什么共同点;
这里讲的python中的decorators是对python中的function/method做装饰,这些修饰仅是当声明一个函数或者方法的时候,才会应用的额外调用。
python中的decorator分 ......

python Eric 的使用

        最近使用python过程中,python界面的编程工具GTK-Python,但是界面的美观性不如Qt-Creator中的Qt-Designer,无法实现设计是视图绘制,有点让人失望。
        网上发现有人介绍python Eric IDE,比较好奇,安装上看看吧:
  &nb ......

Python int类型插入数据库 MySQLdb

 def test2():
 32     db = util.DBUnit('mysql_ab')                                    &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号