How to reference to long variants?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

For example, I have a Dictionary with a value and I have to make changes for it. What should I do?

dict.something.mykey

I saw that there are weakref for making weak references to something but I’m not sure if I can use this for my example.

Can you explain better what your problem is? If you need to modify your value, you can just do dict.something.mykey = value.

Eventually, you can store the last dictionary in a var to shorten the access pattern, because dictionaries are passed around by reference:

var shortcut = dict.something.very.deep
shortcut.mykey = value # Sets dict.something.very.deep.mykey
print(shortcut.mykey)

But you can’t always take a reference to mykey directly, especially if you want to replace it with another value because you still need to access the dictionary which contains it. weakref only works on object types which inherit the Reference class.

Zylann | 2019-02-25 18:37