1

is it possible to convert a string into a name of a table entry? just like

string = "test" y = {test = 123} print y.string 

So if string is "test" it would print y.test if there is such a entry
Hope you understand my question!
Thanks in advance...

2
  • have you read PiL first? Commented Aug 25, 2014 at 15:34
  • 2
    That's actually what the table.name syntax does - it's just a shorthand for table["name"]. Commented Aug 25, 2014 at 17:58

1 Answer 1

4
print(y[string]) 

Be careful with using names such as string for variables, especially globals. You've just overwritten the string table.

Sign up to request clarification or add additional context in comments.

2 Comments

You probably meant print(y[string]).
@PaulKulchenko of course. I was typing from my mobile.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.