1

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)
Samwise
  • 68,105
  • 3
  • 30
  • 44
nwah
  • 13
  • 3
  • Heh, this seems to be a popular question, I ran into another user who asked it just earlier today: https://stackoverflow.com/q/72103508/3141234 The answer to "how do I do this?" is pretty much "Don't. Use a dictionary." – Alexander May 03 '22 at 23:06

1 Answers1

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])
Samwise
  • 68,105
  • 3
  • 30
  • 44