[Tutor] variable name based on variables (expansion?)

John Christian potus98 at yahoo.com
Mon Feb 28 15:05:44 CET 2005


a python 2.3 noob asks:

# I have some lists
GameLogic.varList0=[1,1,1,1]
GameLogic.varList1=[1,1,1,1]
GameLogic.varList3=[1,1,1,1]

# I want to change specific list elements
GameLogic.varList0[2]=0
print GameLogic.varList0
[1,1,0,1]

# But I want the assignment
# to be based on variables
LIST=1
POSITION=2

GameLogic.varList$LIST[$POSITION]=0

# But the variable assignment above does not work.
# Python complains of a syntax error.
# I've also tried variations of eval(), single ticks,
# back ticks, quotes, etc... but I just can't seem
# to get the syntax right.
#
# Can someone please provide a working example?

# In case it matters, here are additional details:
# My python script imports a module named GameLogic.
# My script is called fresh every time it's used; 
# therefore, some variables must be stored in
locations
# such as GameLogic.varA, GameLogic.varB, etc... so 
# they are available for later use. It all works fine
# if I hardcode things, but I'd rather use variables
# since I will eventually have 20 lists with at least
# 10 positions in each list.

TIA!
-potus98


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list