Created
November 28, 2021 05:47
-
-
Save jj-github-jj/eb5e05929466977102f2b2e1af7dc6e1 to your computer and use it in GitHub Desktop.
turn dict to class for autocomplete features of class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Turns a dictionary into a class | |
| # type variable name such as t4. and wait for the class attributes to appear in editor using Kite or other language processors | |
| class Dict2Class(object): | |
| def __init__(self, my_dict): | |
| for key in my_dict: | |
| key2=key.replace(" ","_") #key2 for valid names without spaces for object attributes | |
| key2=key2.replace(":","_") | |
| key2=key2.replace("(","_") | |
| key2=key2.replace(")","_") | |
| setattr(self, key2, my_dict[key]) | |
| def print_attributes (d): | |
| [print (x) for x in dir(d) if "__" not in x ] | |
| t3=LV_array_of_clusters(d) | |
| t4=Dict2Class(t3.arr[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment