Python Forum
How does this definition/directory work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does this definition/directory work?
#1
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)
        pass
When 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,
Reply
#2
It is probably self.grid.xy['xy_id']
Reply
#3
(Nov-06-2018, 06:14 PM)Gribouillis Wrote: It is probably self.grid.xy['xy_id']

Its indeed between '' thank you very much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 426 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 636 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 550 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  [split] Explain the python code in this definition Led_Zeppelin 1 711 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,060 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 1,879 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,526 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  Something wrong with the quotation mark in dictionary definition Mark17 1 1,958 Jan-29-2021, 03:34 PM
Last Post: buran
  I can not get python3 to work... frustrating... something about directory? pythonforumuser 1 1,873 Jan-31-2020, 05:45 PM
Last Post: snippsat
  Definition of .format? (Newbie question) Jan_97 4 2,644 Jul-13-2019, 12:49 PM
Last Post: Jan_97

Forum Jump:

User Panel Messages

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