mysql-python

What's the most efficient way to convert a MySQL result set to a NumPy array?

倖福魔咒の 提交于 2019-11-27 13:41:36
I'm using MySQLdb and Python. I have some basic queries such as this: c=db.cursor() c.execute("SELECT id, rating from video") results = c.fetchall() I need "results" to be a NumPy array, and I'm looking to be economical with my memory consumption. It seems like copying the data row by row would be incredibly inefficient (double the memory would be required). Is there a better way to convert MySQLdb query results into the NumPy array format? The reason I'm looking to use the NumPy array format is because I want to be able to slice and dice the data easily, and it doesn't seem like python is

IndexError: tuple index out of range --— Python

泪湿孤枕 提交于 2019-11-27 13:28:45
问题 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("600x500+10+10") root.title("Ariba") myContainer = Frame(root) myContainer.pack(side=TOP, expand=YES, fill=BOTH) db = MySQLdb.connect ("localhost","root","","chocoholics") s = "Select * from member" cursor = db.cursor() cursor.execute(s) rows = cursor.fetchall() x = rows[1][1] +

Python MySQLDB: Get the result of fetchall in a list

依然范特西╮ 提交于 2019-11-27 12:41:18
I would like to get the result of the fetchall operation in a list instead of tuple of tuple or tuple of dictionaries. For example, cursor = connection.cursor() #Cursor could be a normal cursor or dict cursor query = "Select id from bs" cursor.execute(query) row = cursor.fetchall() Now, the problem is the resultant row is either ((123,),(234,)) or ({'id':123}, {'id':234}) What I am looking for is (123,234) or [123,234]. Be best if I can save on parsing the resulset. Thanks in advance And what about list comprehensions? If result is ((123,), (234,), (345,)) : >>> row = [item[0] for item in

Can't install python mysql library on Mac Mavericks

感情迁移 提交于 2019-11-27 10:58:31
问题 It was working like a charm before the update from Mountain Lion. After the update it is broken and I cannot get the environment up again. Does anybody know how to fix this? The error is bolded, below. fedorius@this:~$ pip install mysql-python Downloading/unpacking mysql-python Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded Running setup.py (path:/private/var/folders/21/zjvwzn891jnf4rnp526y13200000gn/T/pip_build_fedorius/mysql-python/setup.py) egg_info for package mysql-python

MySQL: Get column name or alias from query

橙三吉。 提交于 2019-11-27 10:27:46
I'm not asking for the SHOW COLUMNS command. I want to create an application that works similarly to heidisql, where you can specify an SQL query and when executed, returns a result set with rows and columns representing your query result. The column names in the result set should match your selected columns as defined in your SQL query. In my Python program (using MySQLdb ) my query returns only the row and column results, but not the column names. In the following example the column names would be ext , totalsize , and filecount . The SQL would eventually be external from the program. The

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

馋奶兔 提交于 2019-11-27 09:01:49
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 lock up my database if I don't rewrite the code. Here is what I currently use (partial code): itemBank = [] for row in rows: itemBank.append((tempRow2,tempRow1,tempRow3,tempRow4)) #append data #itemBank List of dictionaries representing data from each row of the table. i.e. ('Item_Name':"Tomatoes",'Item_Price':"10",'Item_In_Stock':"10",'Item_Max':"30") for item in

Installing mysqlclient in Python 3.6 in windows

与世无争的帅哥 提交于 2019-11-27 08:55:15
I want to install MySqlclient on my windows system. I am Currently using Python 3.6. After going through the various post over Stackoverflow, I could Not find the correct way. This is what I have done so far: 1) Installation by using pip pip install mysqlclient . Error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" http://landinghub.visualstudio.com/visual-cpp-build-tools I already have Microsoft Visual C++ installed on my laptop. Some are saying you need 2015 edition. 2) Installation by using wheel file pip install mysqlclient-1.3.13-cp36-cp36m-win

'pip install MySQL-python' fails with 'IndexError'

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 08:26:33
I'm on OSX El Capitan, using Python 2.7 (Anaconda). Launching the command pip install MySQL-python yields: Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/d2/gd004m2s35z5dlyz9mfn6sc40000gn/T/pip-build-FYvb_T/MySQL-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 53, in get_config libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ] File "setup_posix.py"

Python, MySQLdb and escaping table names?

怎甘沉沦 提交于 2019-11-27 07:44:29
问题 I may be missing something obvious, but I can't figure out how my code is different from various examples I see in the online documentation for MySQLdb. I'm fairly new to programming python, more experienced with perl. What I'm trying to do is get into certain good habits early on (like in perl I always start with 'use strict; use warnings'), so I'm trying to ensure I create re-usable functions in an independent file (funct.py) to save me time later on down the line. I've got this function

mysqldb .. 'NoneType' object is not subscriptable

家住魔仙堡 提交于 2019-11-27 07:37:40
问题 This code works fine when the cur.execute() and db.commit() lines are commented out; i.e. if all I do is print the query, this program runs for n number of rows. The problem seems to occur here: player_categories_statistics = cur.fetchone() player_id = player_categories_statistics[0] When I try to insert the result, I get: Traceback (most recent call last): File "test2.py", line 72, in <module> meat = meatgrind(league_name, categories_measurement_statistics) File "test2.py", line 32, in