How does this definition/directory work? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How does this definition/directory work? (/thread-13916.html) |
How does this definition/directory work? - mistertimmy952 - Nov-06-2018 Dear forum, I'm pretty new to python but my program knowledge of other languages is good. I got a piece of code that is working fine. Taken from a example, it has a directory cgi which finds dots on a grid. The struggle for me to find out is how can you have acces to these variables if you want to use in a other definition/function. candidate_grid_ids, cgi_info, grid_id_prev_cost = {}, {}, [] for xy_id, _, cost, _ in paths[-1]: self.grid.get_grid_within_reach(xy_id, xy_id, cost, delta_t, 0, CONFIG.speed, 1, candidate_grid_ids, cgi_info, CONFIG.mot) unique_cgi_with_info = {} for (cgi, cost), xy_id in candidate_grid_ids.items(): self.turtle.dot_xyz_tmp(*self.grid.xy[cgi], color='red4', dotsize=4, update=False) if CONFIG.live_visuals else 0 if cgi not in unique_cgi_with_info or (cgi in unique_cgi_with_info and cost < unique_cgi_with_info[cgi]['cost']): unique_cgi_with_info[cgi] = {'cost': cost, 'xy_id': xy_id,'xy_ids_between': self.grid.reconstruct_between_updates(cgi_info, xy_id, cgi)} self.filter_cgi_with_orientation(unique_cgi_with_info) #-----------------------------------My new function------------------------------------------- def filter_cgi_with_orientation(self, unique_cgi_with_info): for cgi, info in unique_cgi_with_info.items(): x,y = self.grid.xy[xy_id] #This is what I want but xy_id is undefined??? print('\n', cgi, info,'x:',x) passWhen i print the "info" it gives me the xy_id and a bunch of other stuff. But how do I get the xy_id var in my code? I hope you guys understand what I mean, feel free to ask for more info. Grtz, RE: How does this definition/directory work? - Gribouillis - Nov-06-2018 It is probably self.grid.xy['xy_id']
RE: How does this definition/directory work? - mistertimmy952 - Nov-07-2018 (Nov-06-2018, 06:14 PM)Gribouillis Wrote: It is probably Its indeed between '' thank you very much! |