赤色彗星SE 发表于 2010-7-9 17:59

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

本帖最后由 赤色彗星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社区!

eph 发表于 2010-7-9 18:05

shelve

赤色彗星SE 发表于 2010-7-9 18:20

我草楼上我爱你,亲飞!
页: [1]
查看完整版本: python的mysql搜索结果写入了文件后怎么取出来和新搜索对比