[Tutor] Variable help

Tiago Saboga tiagosaboga at terra.com.br
Mon Oct 9 20:24:50 CEST 2006


Hi!

I think your problem was solved, and that the list of lists is the better 
approach indeed. But I'd like to add an answer to a direct question you 
asked:

Em Domingo 08 Outubro 2006 07:47, Tom R. escreveu:
> Basically I want to be able to integrate the value of one variable into
> another variables name. 

I think you would like to do something like: 

=================================
#!/usr/bin/env python
# use of __get_attribute__() function
class players(object):
	player1 = [2,4,8]
	player2 = [3,9,27]
	player3 = [4,16,64]

count = 2
pl = players()
actual_player_string = "player%s" % count

if pl.__getattribute__(actual_player_string)[2]==9:
	print 'It worked.'
===================================

I don't know how to do that if player{1,2,3} are not in a class, or if the 
class is not instanciated. But somebody else can possibly show a way. 

Anyway, as I said, I think you don't need it right now.

Tiago.


More information about the Tutor mailing list