Calling/Passing dictionary objects in python -


I have a class with many functions In one function, I want to create a dictionary object and to make that function any other function I want to call in Can this dictionary be clearly passed?

Here is an example I was doing earlier:

  def dictfunction (self): dictionary = dict () dictionary [sky '] [' cloud '] = 'White' dictionary ['grass'] = 'green' return dictionary  

However, till now I'm calling dictionary objects in other ways:

  def process_function (auto): obj = self.dict_function () print obj ['sky']  

Is there a better way of calling variable in Process_function? There are literally word dictionaries in Python, which are both fast and very good to read in order to make it personally by setting the key.

As described in the comments, if the dictionary is so stable, then any reason for a function No, just store the dictionary and access it.

The only reason is that you will have the dictionary every time if you use it every time you want to change the dictionary without affecting future uses. It seems like the case for your use, however, just you need a dictionary in other tasks.

  class something: def __init __ (self): self.colours = {'sky': 'blue' 'cloud': 'white' 'grass': 'green') DRF draw ( ): Screen. Correct (100, 100, 200, 300, self crawlers ["sky"]) ...  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -