-1

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'
Hussain Ali
  • 156
  • 2
  • 3
  • 14
  • 1
    Your connector is missing : try sql.execute("SHOW TABLES"); – Sahadev Jan 23 '16 at 07: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. – hpaulj Jan 23 '16 at 08:02

1 Answers1

3

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.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231