'Variable contains other variable's name [duplicate]

Is there anyway I could get the value of d3 or in this case the string version of this other variable's name to be used in place of it somehow? So instead of printing "apr_30" it would print the doc using d3?

apr_30 = pd.txt('example.txt')
d3 = ("apr_30")
print(d3)


Solution 1:[1]

Use a dictionary with "apr_30" as a key instead of a variable named apr_30.

d = {
    "apr_30": pd.txt('example.txt')
}
d3 = "apr_30"
print(d[d3])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samwise