Print variable values by their names

Robert Brewer fumanchu at amor.org
Mon Oct 18 19:16:52 CEST 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