Python Forum
PyMySQL return a single dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyMySQL return a single dictionary
#1
Hello,

I'm using pymysql to get all the contents of a table with two columns - user_id and user_name (user_id is the primary key).

is there a way to return a single dictionary with user_id's as keys and user_names as values?
Reply
#2
pass what you get (list/generator of tuples) to dict() function
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql Syntax error in pymysql ilknurg 4 2,287 May-18-2022, 06:50 AM
Last Post: ibreeden
  pymysql can't do SELECT * Pedroski55 3 2,899 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  convert List with dictionaries to a single dictionary iamaghost 3 2,800 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  pymysql won't handle some diacritic characters awarren2001AD 0 1,235 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL - ROW_NUMBER in SQL statement JayCee 1 2,339 Apr-12-2020, 08:40 PM
Last Post: JayCee
  pyMySQL How do I get the row id JayCee 3 2,667 Apr-12-2020, 08:38 PM
Last Post: JayCee
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 6,564 May-29-2019, 02:27 AM
Last Post: heiner55
  How to take a single value from dictionary ginjaninja247 1 1,696 May-28-2019, 12:34 PM
Last Post: buran
  pymysql: formating ouput of query wardancer84 18 8,176 Oct-04-2018, 01:54 PM
Last Post: wardancer84
  pymysql ifnull aland 4 3,938 Sep-06-2018, 05:58 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020