python实现mysql的单引号字符串过滤方法

yipeiwu_com5年前Python基础

本文实例讲述了python实现mysql的单引号字符串过滤方法。分享给大家供大家参考,具体如下:

最主要用这个函数,可以处理MySQLdb.escape_string(content).

class Guide:
 def __init__(self):
  self.time_zone = 7*3600 #设置时区
  self.now_time = int(time.time()) + self.time_zone #取得当前时间
   #本地
  self.gamedb_model = mysql_conn.MySQLHelper(config.game_db['host'], config.game_db['user'],
    config.game_db['password'], config.game_db['db_name'],
    config.game_db['port'])
  #远程
  self.remote_model = mysql_conn.MySQLHelper(config.remote_db['host'], config.remote_db['user'],
    config.remote_db['password'], config.remote_db['db_name'],
    config.remote_db['port'])
  #game center
  self.commdb_model = mysql_conn.MySQLHelper(config.comm_db['host'], config.comm_db['user'],
   config.comm_db['password'], config.comm_db['db_name'],
   config.comm_db['port'])
 def index(self):
  #拿到第二天未登陆的用户
  for line in open("2014.3.20_global_ips.txt"):
   list = line.split('||')
   l = len(list)
   if l == 3:
    info = ''
   else:
    info = MySQLdb.escape_string(list[3])
   self.commdb_model.insert('ip_area',{'start_ip':list[0],'end_ip':list[1],'area':list[2],'info':info})
if __name__ =="__main__":
 keep = Guide()
 keep.index()

希望本文所述对大家python程序设计有所帮助。

相关文章

Python使用numpy模块实现矩阵和列表的连接操作方法

Numpy模块被广泛用于科学和数值计算,自然有它的强大之处,之前对于特征处理中需要进行数据列表或者矩阵拼接的时候都是自己写的函数来完成的,今天发现一个好玩的函数,不仅好玩,关键性能强大,...

Python 数据处理库 pandas进阶教程

Python 数据处理库 pandas进阶教程

前言 本文紧接着前一篇的入门教程,会介绍一些关于pandas的进阶知识。建议读者在阅读本文之前先看完pandas入门教程。 同样的,本文的测试数据和源码可以在这里获取: Github:p...

Python3按一定数据位数格式处理bin文件的方法

Python3按一定数据位数格式处理bin文件的方法

因为研究生阶段经常用MATLAB作图,处理数据,但是MATLAB太过于庞大,不方便,就想用python处理。 问题:我们通常处理的最原始的数据是bin文件,打开后如下所示,是按16进制形...

给我一面国旗 python帮你实现

给我一面国旗 python帮你实现

本文实例为大家分享了Python之给我一面国旗的具体代码,供大家参考,具体内容如下 1、“给我一面国旗@微信官方” 今天“给我一面国旗@微信官方”刷爆了朋友圈,我也蹭波热度,出个Pyth...

Django 前后台的数据传递的方法

Django 从后台往前台传递数据时有多种方法可以实现。 最简单的后台是这样的: from django.shortcuts import render def main_page...