Question:Programming a game grid ...

Chris Angelico rosuav at gmail.com
Wed Jun 27 19:35:59 EDT 2012


On Thu, Jun 28, 2012 at 9:24 AM, David <dwblas at gmail.com> wrote:
> First, you should be getting an error on
> vars()[var] = Button(f3, text = "00", bg = "white")
> as vars() has not been declared and it does not appear to be valid Python syntax.

It's valid syntax, but highly inadvisable. What it does is call the
vars() function, then dereference its argument for assignment -
perfectly legal when the function returns a dictionary, which vars
does. But check the docs:

http://docs.python.org/library/functions.html#vars

It's intended to be read, NOT written. It's entirely possible that
this works at module level, but should not be relied on. Also, other
Python implementations or even other versions of the same Python could
behave differently.

ChrisA



More information about the Python-list mailing list