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

yipeiwu_com6年前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列表与元组详解实例

在这章中引入了数据结构的概念。数据结构是通过某种方式组织在一起的数据元素的集合。在python中,最基本的数据结构就是序列。序列中的每个元素被分配一个序号,即元素的位置,也被称为索引。注...

Python有参函数使用代码实例

这篇文章主要介绍了Python有参函数使用代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.给定验证码长度n,生成随机验证码...

Python3.5集合及其常见运算实例详解

本文实例讲述了Python3.5集合及其常见运算。分享给大家供大家参考,具体如下: 1、集合的定义:集合是一个无序的、无重复的数据的数据组合。 2、集合的特征: (1)去除重复元素:将一...

解决Mac安装scrapy失败的问题

今天打算弄个爬虫,想来想去打算用python弄一个。之前了解到scrapy这个库是个不错的选择,于是开始折腾。可惜第一步就挂了。 安装scrapy库就不成功: Installing...

代码实例讲解python3的编码问题

代码实例讲解python3的编码问题

python3的编码问题。 打开python开发工具IDLE,新建‘codetest.py'文件,并写代码如下: import sys print (sys.getdefaulte...