Python Forum
Help accessing elements of list of dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help accessing elements of list of dictionaries
#7
Ok. Hopefully this will be better.

my_button1 = Button(root, text = "Load Race Files", width = 15, command = load_racefiles) 
my_button1.place(x=443, y=150)

def load_racefiles() :
	global Race_date

	count = 0
	master_race_file = []
	rows = 100
	columns = 100
	horse_array = [0 for i in range(rows)] 
	file_name = StringVar()
	f_name = StringVar()
	
	fd =    open("dirpath", "r") 
	file_dir = (fd.read())
	fd.close()
	os.chdir(file_dir)
	for f in os.listdir(file_dir): 
		file_name, file_ext = os.path.splitext(f)
		f_name = file_name + file_ext
		file_name = file_name.strip()[3:]
		line_counter = 0
		if file_name == Race_date and file_ext == ".jcp":
			with open(f_name, "r") as csv_file:
				csv_reader = csv.reader(csv_file)
				
				for line in csv_reader:

                     h = {'track' : line[0],
                     'horse_name' : line[44]
                          }
                    master_race_file.append(h ) 
					
				my_labeldone= Label( text ="Downloading Complete", fg= "black", font = ("sans_serif" , 16)).place(x=500, y=500)
This all works. Now I need to access the dictionaries to see if the track name and the race date selected by the user previous to load_files function is called are equal so I can put that line in a separate smaller list so I can then manipulate the data.

I hope this is easier to deal with.
Reply


Messages In This Thread
RE: Help accessing elements of list of dictionaries - by Milfredo - Sep-07-2020, 01:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 643 Apr-29-2024, 04:38 PM
Last Post: Calab
  unable to remove all elements from list based on a condition sg_python 3 488 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 510 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Access list of dictionaries britesc 4 1,115 Jul-26-2023, 05:00 AM
Last Post: Pedroski55
  Checking if a string contains all or any elements of a list k1llcod3 1 1,150 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 2,044 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,229 May-17-2022, 11:38 AM
Last Post: Larz60+
  Why am I getting list elements < 0 ? Mark17 8 3,207 Aug-26-2021, 09:31 AM
Last Post: naughtyCat
  Looping through nested elements and updating the original list Alex_James 3 2,175 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Extracting Elements From A Website List knight2000 2 2,331 Jul-20-2021, 10:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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