How do I combine instance+string for variable

Erik Max Francis max at alcyone.com
Fri Aug 1 19:56:17 EDT 2003


Marc wrote:

> I have several instances of telnet connections that I label
> conn2,conn3, etc. Later when I want to scroll through all of these I
> wanted to do something like this:
> 
>     for int in range(2, 9):
>             use... conn+str(int) {I'm passing it into another
> function}
> 
> I can't get it to work. I've tried using setattr and eval, but nothing
> seems to work. Can I get a little help.

You probably meant

	connection = eval('conn' + str(connectionNumber))

although in something like this, it seems like a dictionary, with the
keys being integers, would be a far better solution.  Then you'd simply
write:

	connections[connectionNumber]

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ To understand is to forgive, even oneself.
\__/  Alexander Chase




More information about the Python-list mailing list