Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cursor.fetchall() to list

And what about list comprehensions? If result is ((123,), (234,), (345,)):

>>> row = [item[0] for item in cursor.fetchall()]
>>> row
[123, 234, 345]

If result is ({'id': 123}, {'id': 234}, {'id': 345}):

>>> row = [item['id'] for item in cursor.fetchall()]
>>> row
[123, 234, 345]

--César
Comment

PREVIOUS NEXT
Code Example
Python :: python checking for NoneType 
Python :: flatmap in python 
Python :: python extract email attachment 
Python :: python for in for in 
Python :: python recursion factorial 
Python :: input function python 
Python :: chrome profiles user open with python 
Python :: sns boxplot 
Python :: smallest number of 3 python 
Python :: Change Python interpreter in pycharm 
Python :: python backslash in string 
Python :: notebook cell print output to file 
Python :: format date string python 
Python :: Yahoo! Finance pyhton 
Python :: spark.read.load 
Python :: numpy array divide each row by its sum 
Python :: how to use modulo in python 
Python :: heroku[web.1]: Process exited with status 3 
Python :: Python list files only in given directory 
Python :: datetime column only extract date pandas 
Python :: django model example 
Python :: save image to database using pillow django 
Python :: upload file to s3 
Python :: tqdm command that works both in notebook and lab 
Python :: python round 1 decimal place 
Python :: python convert 
Python :: python garbaze collection 
Python :: print without newline 
Python :: pandas.get_dummies 
Python :: python get total gpu memory 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =