找回密码
 立即注册
搜索
查看: 2000|回复: 2

[软件] python的mysql搜索结果写入了文件后怎么取出来和新搜索对比

[复制链接]
     
发表于 2010-7-9 17:59 | 显示全部楼层 |阅读模式
本帖最后由 赤色彗星SEXY 于 2010-7-9 18:02 编辑

import MySQLdb
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
class mysqlcommand:
        def __init__(self):
                self.sqlcommand = 'select * from ptgame_v_dlpvalues order by userid limit 10'
        def select(self,ip,username,password,dbname):
                dbLink = MySQLdb.connect(host=ip,user=username,passwd=password,db=dbname)
                sqlcursor = dbLink.cursor()
                list = sqlcursor.execute("SET NAMES utf8")
                list = sqlcursor.execute(self.sqlcommand)
                rows = sqlcursor.fetchall()
                sqlcursor.close()
                dbLink.close()
                return rows

p = mysqlcommand()
rows=p.select('192.168.1.132','mysql','123456','wrz_db3')
file = open('/root/test','wb+')
for row in rows:
        for col in row:
                if col is row[-1]:
                        file.write(str(col) + "\n")
                else:
                        file.write(str(col) + ",")

file.close()


这样只能用str方式取出来,不方便和新搜索结果比较啊,直接tuple()读出来的内容分割不正确!如何才能还原写入的内容成原来的tuple类型呢?
顺便求个比较好的python社区!
回复

使用道具 举报

发表于 2010-7-9 18:05 | 显示全部楼层
shelve
回复

使用道具 举报

     
 楼主| 发表于 2010-7-9 18:20 | 显示全部楼层
我草楼上我爱你,亲飞!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|Stage1st ( 沪ICP备13020230号-1|沪公网安备 31010702007642号 )

GMT+8, 2025-9-18 07:28 , Processed in 0.069493 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表