易截截图软件、单文件、免安装、纯绿色、仅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列表和字典的方法总结

列表方法:


方法
说明
append( item )
在列表末尾插入(item )
count( element )
返回element在列表中出现的次数
extend( newlist )
将newlist的元素插入列表末尾
index( element )
返回element在列表中的索引,如果不存在,则引发ValueError异常
insert( index , item )
在index ......

用Python实现简单的遗传算法

用Python实现简单的遗传算法
2010-02-15 14:00
这几天一直在用Python写一个简单的遗传算法,好自己拿来实验。断断续续的折腾了几天,今天下午终于写了一个简单的出来。整个代码还是仿照《游戏编程中的人工智能技术》中的代码来写的。如果想简单的学习一下遗传算法以及简单应用《游戏编程中的人工智能技术》是不错的选择。 ......

python的C、c++扩展

python的C、c++扩展
http://blog.chinaunix.net/u3/110228/showart_2148725.html
python的强大不仅表现在其功能上,而且还表现在其扩展能力上。
使用C/C++很容易编写python的模块,扩展python的功能。
同时将性能要求比较高的代码使用C/C++编写,能更好的弥补
脚本语言执行速度慢的缺陷。
1. python的C语言扩展
1.1 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号