"AttributeError: cursor", how to fix it (Python)?
-
I'm trying to set up a python script that connects to a database. After some searching on the world wide web I now have some code which should do just about fine, but I get the following error AttributeError: cursor. I probably have to install a certain package (I'm using Ubuntu). Here's my code: import MySQLdb DB = 'testdb' DB_HOST = 'localhost' DB_USER = 'root' DB_PASSWORD = '' conn = MySQLdb.connection(db=DB, host=DB_HOST, user=DB_USER, passwd=DB_PASSWORD) cursor = conn.cursor () sql = """show tables;""" cursor.execute(sql) results = cursor.fetchall() cursor.close() conn.close() Please help
-
Answer:
If you are able to import MySQLdb without any problem, then you don't need to install anything else. Try MySQLdb.connect() instead of MySQLdb.connection()
dhldhldh... at Yahoo! Answers Visit the source
Related Q & A:
- How To Fix Blackberry Jvm Error 517?Best solution by Yahoo! Answers
- How To Fix Jvm Error 517 On Blackberry?Best solution by Yahoo! Answers
- How To Fix Blurry Led Tv?Best solution by Yahoo! Answers
- How to update a python package?Best solution by Stack Overflow
- How to remotly debug python on my apache?Best solution by blog.jetbrains.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.