Print variable values by their names

Robert Brewer fumanchu at amor.org
Mon Oct 18 13:16:52 EDT 2004


Michael Krasnyk wrote:
> import sys
> for str in dir(sys): print str
> 
> Will be printed only variable names, but I need values from 
> list of variable names.

import sys
for name in dir(sys):
    print name, getattr(sys, name)


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list