How to get the 'name' of an int

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Feb 28 05:22:50 EST 2003


"Hans Brand" <Hans.Brand at BrandInnovators.com> wrote in 
news:b3ncbr$ij4$1 at reader08.wxs.nl:

> I just wondered if I could write something like:
> 
> for item in (a long list of variables):
>     print "%s = %s" %(name(item), item)
> 
> without having to know each name of each variable
> 

You have to know the name to put it in the long list. If what you are 
asking is to be able to print out the names and values without having to 
type the names twice then that is easy, just start with the names as 
strings:

for item in ('var1', 'var2'):
    print '%s=%s' % (item, vars[item])

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list