Python Forum
AttributeError: 'list' object has no attribute 'values'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'list' object has no attribute 'values'
#1
I have a query. My query returns the result that i want as a dictionary.

Like:

[{'community_string': 'public'}, {'community_string': 'private'}]
I want to use only public and private as a string. For doing it, i wrote my code like that:

query= "SELECT community_string FROM nat_snmp_string WHERE status ='enable'"
cursor = connection.cursor(dictionary=True)
cursor.execute(query)
com_str = cursor.fetchall()
com_str_string = com_str.values()
cmnyt_str = json.dumps(list(com_str))
print(cmnyt_str)  
cmd_line = cmnyt_str.replace(':','')
cmd_line = cmd_line.replace('"','')
cmd_line = cmd_line.replace(']','')
cmd_line = cmd_line.replace('[','')
  
but it gives me AttributeError: 'list' object has no attribute 'values' error.
How can i solve this issue?
Thank you for your helps.
Reply


Messages In This Thread
AttributeError: 'list' object has no attribute 'values' - by ilknurg - Jan-19-2022, 07:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out incidence values for Class Object SquderDragon 3 334 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  Copying the order of another list with identical values gohanhango 7 1,213 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,310 Nov-03-2023, 05:35 PM
Last Post: huzzug
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 825 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,835 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,616 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 800 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 4,047 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 784 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,240 Jun-09-2023, 04:57 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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