Michael Krasnyk wrote:
How can I print variable values by their names?
For example:
import sys
for str in dir(sys): print str
Will be printed only variable names, but I need values from list of
variable names.
vars(module) gives you the module's global dictionary:
import sys
for name, value in vars(sys).items():
.... print name, "=", repr(value)
....
setrecursionlimit = <built-in function setrecursionlimit>
getfilesystemencoding = <built-in function getfilesystemencoding>
stdout = <open file '<stdout>', mode 'w' at 0x40335060>
[snip]
Peter