2016-01-23 56 views
-1

我是新的python时我试图运行下面的蟒蛇类型错误:执行()失踪1人需要的位置参数:“ARGS”

from distutils.util import execute 
from gi.repository import Gtk 
import mysql.connector 

class MyWindow(Gtk.Window): 
con = mysql.connector.connect(user='root', password='', host='localhost', database='mydatabase') 
sql = con.cursor() 
test = Gtk.Button(label="test") 
    save_buy.connect("clicked", self.test_click) 
    box1.pack_start(test, True, True, 0) 
def test_click(self, widget): 
    self.sql = execute("SHOW TABLES") 
    print(self.sql.fetchall()) 

,当我在测试按钮点击我得到

TypeError: execute() missing 1 required positional argument: 'args' 
+1

您的连接缺失: 尝试 sql.execute(“SHOW TABLES”); – Sahadev

+0

你为什么使用'distutils'?这只是通过搜索'execute'找到的东西吗?它与'mysql'无关。而不是我期望初学者也可以使用的东西。 – hpaulj

回答

3

错误很明显。您必须将其他参数传递给execute

请注意,您正在从distutils.util导入execute。相关文件是here

execute(func, args[, msg=None, level=1])

Invokes distutils.util.execute() . This method invokes a Python function func with the given arguments args , after logging and taking into account the dry_run flag.

而且你传递一个字符串而不是调用。您可能会将该执行函数与接受SQL语句的mysql包中的其他函数混淆。例如,光标有一个execute方法,所以你可能想改为sql.execute("SHOW TABLES")

+0

我需要执行的MySQL,我无法在包中找到要添加到我的项目 –

+0

@HussainAli你读过这个问题:http://stackoverflow.com/q/372885/510937? – Bakuriu

相关问题