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程序设计有所帮助。

相关文章

win系统下为Python3.5安装flask-mongoengine 库

环境: windows 10、python 3.5、flask-mongoengine 0.8.2或0.9.0 使用以下命令安装 flask-mongoengine pip instal...

分分钟入门python语言

Python 是 90 年代初由 Guido Van Rossum 创立的。它是当前最流行的程序语言之一。它那纯净的语法令我一见倾心,它简直就是可以运行的伪码。 请注意:本文以 Pyth...

python的set处理二维数组转一维数组的方法示例

for splitValue in set(dataset[:, featureIndex].tolist()): 首先set是一个无序,无重复的数据结构,所以很多时候使用它来进行去重;...

Python检查ping终端的方法

菜鸟一枚,写着试了试,虽说有点杂乱,但还是能用,我是在linux下运行的 大致说下过程: 1、把需要ping的网段中所有ip存到数组中(我是放到数组中了,其实直接for循环,一个个的也行...

Python类的专用方法实例分析

本文实例讲述了Python类的专用方法。分享给大家供大家参考。具体分析如下: Python 类可以定义专用方法,专用方法是在特殊情况下或当使用特别语法时由 Python 替你调用的,而不...