How can I check the result of mysql query in python?

I've seen lines like op.execute("CREATE LANGUAGE plpgsql") in other scripts in my system so thought I could do similar with the following.

op.execute("SHOW TABLES LIKE 'table_name'")

How can I check the result from this and then do stuff based on existence or not?

I tried result = op.fetchone() but this is incorrect.
  AttributeError: 'module' object has no attribute 'fetchone'

and
  if not op.execute("SHOW TABLES LIKE 'agents'"):
micktAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Do you have anything working?  Which MySQL driver are you using?

http://dev.mysql.com/downloads/connector/python/
micktAuthor Commented:
Server version: 5.6.31-ndb-7.4.12-cluster-gpl

Multiple DB and all working.

Trying to do/not do something based on the existence of a table.
Dave BaldwinFixer of ProblemsCommented:
I believe you have to process 'SHOW TABLES' and similar queries just like a SELECT query because that is what they are.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

micktAuthor Commented:
Sorry, I'm not following, can you please clarify for me?
micktAuthor Commented:
I cam across this too.

    cursor.execute("SHOW TABLES LIKE 'table_name'")
    result = cursor.fetchone()
    if result:
        "There is a table named table_name."
    else:
        do stuff

but it complains about cursor
micktAuthor Commented:
II resolved as follows:

    tbl = op.execute("SHOW TABLES LIKE 'table_name'")
    if not tbl:
        return

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Glad you got it figured out.  I had to get some sleep.
micktAuthor Commented:
Answers question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.