Skip to content

Instantly share code, notes, and snippets.

@jj-github-jj
Created November 28, 2021 05:47
Show Gist options
  • Save jj-github-jj/eb5e05929466977102f2b2e1af7dc6e1 to your computer and use it in GitHub Desktop.
Save jj-github-jj/eb5e05929466977102f2b2e1af7dc6e1 to your computer and use it in GitHub Desktop.
turn dict to class for autocomplete features of class
# 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