Skip to content
Advertisement

Global dict name in a variable

I want to have more dict’s in my init.py and I want to set its name in a variable. But it wouldn’t detect it as the name.

My Program:

JavaScript

StackOverflowinit.py:

JavaScript

I expect that it give the color and brand from the chosen car. But I get this error:

JavaScript

Advertisement

Answer

Since Python 3.7, you can use getattr on modules.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement