将 Maya 2011 与 Mysqldb 连接
我在 Windows 7(64 位)机器上使用 Maya 2011(64 位)和 MySQL 5.5(64 位)。我尝试通过python连接maya和Mysqldb。所以我将连接器文件复制到maya\python\lib\site 包中。
我能够导入 MYsqldb 模块,没有任何错误。但是当我尝试调用光标对象(用于查询)时,我发现Maya无法识别光标对象。
这是我的示例代码:
import MySQLdb as mb
import maya.cmds as cmds
def mysql_connect(hostname, username, password, dbname):
db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)
db = mysql_connect("localhost", “root”, “test”, “mydbt")
dbcursor = db.cursor()
dbcursor.execute("select * from maya")
But the code throws the following error :
错误:AttributeError:'NoneType'对象没有属性'cursor'#
我尝试验证环境路径变量,替换连接器文件,但问题仍然存在。
由于是初学者,我无法确定确切的问题。
我请求您提出宝贵的建议
I am using Maya 2011(64bit) and MySQL 5.5 (64 bit) in Windows 7 (64 bit) machine. I tried to connect maya with Mysqldb through python. So i copied the connector files into maya\python\lib\site packages.
I was able to import MYsqldb module without any error. But when i tried call the cursor object (for querying), I found that Maya is not recognizing the cursor object.
Here is my sample code:
import MySQLdb as mb
import maya.cmds as cmds
def mysql_connect(hostname, username, password, dbname):
db = mb.connect(host=hostname,user=username,passwd=password,db=dbname)
db = mysql_connect("localhost", “root”, “test”, “mydbt")
dbcursor = db.cursor()
dbcursor.execute("select * from maya")
But the code throws the following error :
Error: AttributeError: ‘NoneType’ object has no attribute ‘cursor’ #
I tried verifying the env-path variables, replacing the connector files but the problem persists.
Since being a beginner, i am un-able to identify the exact issue.
I request for your valuable suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有从 mysql_connect 函数返回任何内容。所以它返回
None
。当您这样做时:db
变为None
。尝试改变:话虽
这么说,我不确定定义一个函数来制作单个东西是否有用。最好有这样的东西:
You are not returning anything from
mysql_connect
function. So it returnsNone
. When you do:db
becomesNone
. Try changing:with
That being said, I'm not sure defining a function to make a single thing is useful. Better to have something like this:
在这里,您有两件事分配给
db
。看来mysql_connect("localhost", "root", "test", "mydbt")
返回None
,所以当你调用db.cursor( )
之后,您会收到该错误。请确保您正确覆盖了
db
变量(在本例中,您似乎没有正确覆盖)。Here, you have two things assigned to
db
. It appears thatmysql_connect("localhost", “root”, “test”, “mydbt")
is returningNone
, so when you calldb.cursor()
later, you get that error.Make sure you're overwriting the
db
variable correctly (in this case, it looks like you aren't).