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
  Not including a constructor __init__ in the class definition... bytecrunch 3 301 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  How to make a test data file for the full length of definition? MDRI 6 1,073 Apr-16-2021, 01:47 AM
Last Post: MDRI
  Something wrong with the quotation mark in dictionary definition Mark17 1 653 Jan-29-2021, 03:34 PM
Last Post: buran
  I can not get python3 to work... frustrating... something about directory? pythonforumuser 1 713 Jan-31-2020, 05:45 PM
Last Post: snippsat
  Definition of .format? (Newbie question) Jan_97 4 1,238 Jul-13-2019, 12:49 PM
Last Post: Jan_97
  function definition (pycharm) raulseangarciaroberts 3 3,118 Dec-25-2017, 03:11 PM
Last Post: raulseangarciaroberts
  Character Definition Like ASCII llarix1 2 2,364 Jul-11-2017, 01:25 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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