0

i'm new at python i tried to run the following

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()) 

and when i click on test button i get

TypeError: execute() missing 1 required positional argument: 'args'
2
  • 1
    Your connector is missing : try sql.execute("SHOW TABLES"); Commented Jan 23, 2016 at 7:19
  • Why are you using distutils? Is that just something you found by searching for execute? It has nothing to do with mysql. And not something I'd expect a beginner to use either. Commented Jan 23, 2016 at 8:02

1 Answer 1

4

The error is pretty clear. You have to pass an other argument to execute.

Note that you are importing execute from distutils.util. The relevant documentation is 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.

Moreover you are passing a string instead of a callable. You are probably confusing that execute function with an other function from the mysql package which accepts SQL statements. For example the cursor has a execute method, so you maybe wanted to do sql.execute("SHOW TABLES") instead.

Sign up to request clarification or add additional context in comments.

2 Comments

i need the execute of mysql and i can not find in the package to add to my project
@HussainAli Did you read this question: stackoverflow.com/q/372885/510937 ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.