python transform=none_python 错误:"'NoneType' object has no attribute 'execute'" 求解 谢谢!

importMySQLdbclassmysql():def__enter(self):#InanyMultiTaskingenvironmenttheabilitytoatomicallyexecuteasectionofcodeisveryimportant.Tocreateacriticalsectioninstacklessself...

import MySQLdb

class mysql():

def __enter(self):#In any MultiTasking environment the ability to atomically execute a section of code is very important. To create a critical section in stackless

self.__tasklet = stackless.getcurrent()

self.__atomic = self.__tasklet.set_atomic(True)

def Connect(self, *args, **kwargs):

self.conn = MySQLdb.connect(*args, **kwargs)

self._cursor = self.conn.cursor()

self._trans = False

#After mysql-python 1.12, * Turn autocommit off initially

#But here we enable autocommit again.

self.conn.autocommit(True)

self._args = args

self._kwargs = kwargs

return self.conn

#MySQL python Version 1.1.2

# * Remove Connection.begin(); use SQL BEGIN or START TRANSACTION instead self.conn.begin()

def Begin(self):

#If already start transaction, donn't restart it. maybe commit the last trans

if self._trans:return

self._cursor.execute("BEGIN")

self._trans = True

def Insert(self, sql, para ):

self.__enter()

_cursor = self.conn.cursor()

_cursor.execute(sql, para)

ret = _cursor.lastrowid

_cursor.close()

self.__exit()

return ret

f=mysql()

f.Connect(user="root",passwd="12345",host="localhost",db="yingtest")

f.Begin()

f.Insert("insert into note values('%s,%s')"%[4,'yes'])

运行错误:

Traceback (most recent call last):

File "C:\Documents and Settings\Administrator\桌面\12345.py", line 38, in

ule>

f.Begin()

File "C:\Documents and Settings\Administrator\桌面\12345.py", line 23, in Begi

n

self._cursor.execute("BEGIN")

AttributeError: 'NoneType' object has no attribute 'execute'

按照分析来讲 我想是f.Connect(user="root",passwd="12345",host="localhost",db="yingtest")这句没运行成功 求分析 求解释..

在 self.conn = MySQLdb.connect(*args, **kwargs)

和 self._cursor = self.conn.cursor()

后面各打印了print self.conn和print self._cursor 运行结果:

None

问题就在self._cursor = self.conn.cursor()这里 求分析 求解释..

谢谢!

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值