I'm trying to create a class based on the dictionary. All the values in the dictionary have notation e.g. 'key1.key2.key3' where key1, key2 are parents in the dictionary tree, and key3 is the current key. So the value of key3 is a string 'key1.key2.key3'. This is to make sure that I can change the name of e.g. key2 in only one location.
The naive code for that would be:
class Key1:
class Key2:
KEY3 = 'key1.key2.key3'
KEY4 = 'key1.key2.key4'
Now I can access path 'key1.key2.key3' by calling Key1.Key2.KEY3
But if I want to change 'key1' to some other name, I need to change 'key1' if many values.
I've tried to make some attributes for the classes:
class Key1:
name = 'key1'
class Key2:
name = Key1.name + '.key2'
KEY3 = Key2.name + '.key3'
KEY4 = Key2.name + '.key4'
Python says name 'Key1' is not defined.
Key2is being definedKey1is not defined yet. Also,Key2is also not defined yet, so you can't accessKey1norKey2. You'll have to think about another design - DeepSpaceclass Key2(Key1)(same indent level) and it should work - Plopp