How do I import variable packages in Python like using variable variables ($$) in PHP?

Python doesn’t have a feature that’s directly equivalent to PHP’s “variable variables”. To get a “variable variable”‘s value (or the value of any other expression) you can use the eval function. foo = “Hello World” print eval(“foo”) However, this can’t be used in an import statement. It is possible to use the __import__ function to … Read more

How can I select a variable by (string) name?

In most cases like this, an ordinary dictionary will do the job just fine. >>> get_ext = {‘text’: [‘txt’, ‘doc’], … ‘audio’: [‘mp3’, ‘wav’], … ‘video’: [‘mp4’, ‘mkv’] … } >>> >>> get_ext[‘video’] [‘mp4’, ‘mkv’] If you really want or need a function (for which there can be valid reasons) you have a couple of … Read more