mysql-python

python mysql.connector DictCursor?

python mysql.connector DictCursor? Question: In Python mysqldb I could declare a cursor as a dictionary cursor like this: cursor = db.cursor(MySQLdb.cursors.DictCursor) This would enable me to reference columns in the cursor loop by name like this: for row in cursor: # Using the cursor as iterator city = row[“city”] state = row[“state”] Is it possible …

Total answers: 5

ImportError: No module named MySQLdb

ImportError: No module named MySQLdb Question: I am referring the following tutorial to make a login page for my web application. http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out–net-29982 I am having issue with the database. I am getting an ImportError: No module named MySQLdb when I execute http://127.0.0.1:5000/testdb I have tried all possible ways to install python mysql, the one mentioned …

Total answers: 16

Install mysql-python (Windows)

Install mysql-python (Windows) Question: I’ve spent hours trying to make Django work on my computer. The problem is that I can’t install the mysql-python package. I’m running Windows 7 64bit. This is what I’ve tried: I have downloaded easy_install I have downloaded Cygwin64 to be able to run Linux commands (Win cmd was driving me …

Total answers: 11

MySQLdb Python insert %d and %s

MySQLdb Python insert %d and %s Question: Precursor: MySQL Table created via: CREATE TABLE table(Id INT PRIMARY KEY NOT NULL, Param1 VARCHAR(50)) Function: .execute(“INSERT INTO table VALUES(%d,%s)”, (int(id), string) Output: TypeError: %d format: a number is required, not a str I’m not sure what’s going on here or why I am not able to execute …

Total answers: 4

IndexError: tuple index out of range —– Python

IndexError: tuple index out of range —– Python Question: Please Help me. I’m running a simple python program that will display the data from mySQL database in a tkinter form… from Tkinter import * import MySQLdb def button_click(): root.destroy() root = Tk() root.geometry(“600×500+10+10”) root.title(“Ariba”) myContainer = Frame(root) myContainer.pack(side=TOP, expand=YES, fill=BOTH) db = MySQLdb.connect (“localhost”,”root”,””,”chocoholics”) s …

Total answers: 5

How can I use executemany to insert into MySQL a list of dictionaries in Python

How can I use executemany to insert into MySQL a list of dictionaries in Python Question: I’m currently using MySQL and Python to scrape data from the web. Specifically, I am scraping table data and inserting it into my database. My current solution works, but I feel it is extremely inefficient and will most likely …

Total answers: 2

cursor.fetchall() vs list(cursor) in Python

cursor.fetchall() vs list(cursor) in Python Question: Both methods return a list of the returned items of the query, did I miss something here, or they have identical usages indeed? Any differences performance-wise? Asked By: NZal || Source Answers: list(cursor) works because a cursor is an iterable; you can also use cursor in a loop: for …

Total answers: 5

How to insert pandas dataframe via mysqldb into database?

How to insert pandas dataframe via mysqldb into database? Question: I can connect to my local mysql database from python, and I can create, select from, and insert individual rows. My question is: can I directly instruct mysqldb to take an entire dataframe and insert it into an existing table, or do I need to …

Total answers: 9

Visibility of global variables in imported modules

Visibility of global variables in imported modules Question: I’ve run into a bit of a wall importing modules in a Python script. I’ll do my best to describe the error, why I run into it, and why I’m tying this particular approach to solve my problem (which I will describe in a second): Let’s suppose …

Total answers: 9

ImportError: No localization support for language 'eng' in python

ImportError: No localization support for language 'eng' in python Question: I am getting ImportError: No localization support for language ‘eng’ when using MySQL Connector in Python. My Traceback is as below. Traceback (most recent call last): File “DB_Module.py”, line 151, in QueryDatabase File “\shareappModulesmysqlconnector__init__.py”, line 44, in Connect File “\shareappModulesmysqlconnectorconnection.py”, line 106, in __init__ File …

Total answers: 3