易截截图软件、单文件、免安装、纯绿色、仅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 初体验

windows下
1 下载python安装包, 一路下去安装
2 下载mysqldb安装
3 下载django文件, dyango-admin.py install 完成
-----如果启动后报错import error: dll load failed. 需要在site-package下增加dll: libguide40.dll  libmmd.dll  libmySQL.dll
创建应用后, manage.py 的program argument中应 ......

python 的函数Decorators

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

python31与C交互

1.c调用python:
   实例代码:
main.c调用test.py的
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//main.c
#include <windows.h>
......

python Eric 的使用

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

python中datetime的比较方法使用


python中的datetime module是专门处理时间相关内容的模块,功能很强大,但是反而显得比较复杂。
一下代码是用来求从mysql中取到的timestamp和当前时间比较,求时间差的方法
import datetime
lasttime=a.get_last_timestamp(sid=40)[-1]["last_time"] #取到timestamp
delta = datetime.datetime.now()-lasttime   # ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号