By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

A simple array in Python

P: n/a
Hi,

I have the following enum -

class State:
Fire = 0
Water = 1
Earth = 2

And I want a variable which holds a value for each of these states,
something like -

myState1[State.Fire] = 10
myState1[State.Earth] = 4

myState2[State.Fire] = 20
myState2[State.Earth] = 24

How do I do this?

Thanks Barry.

Jan 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
bg***@yahoo.com wrote:
Hi,

I have the following enum -

class State:
Fire = 0
Water = 1
Earth = 2

And I want a variable which holds a value for each of these states,
something like -
class State:
Fire = 0
Water = 1
Earth = 2
myState = {} # It is a dictionary, see
http://docs.python.org/tut/node7.htm...00000000000000
myState[State.Fire] = 20
myState[State.Earth] = 24
print myState

{0: 20, 2: 24}
Jan 9 '07 #2

P: n/a
<bg***@yahoo.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.com...
Hi,

I have the following enum -

class State:
Fire = 0
Water = 1
Earth = 2

And I want a variable which holds a value for each of these states,
something like -

myState1[State.Fire] = 10
myState1[State.Earth] = 4

myState2[State.Fire] = 20
myState2[State.Earth] = 24

How do I do this?

Thanks Barry.
How about (arrays are sooo last century):

class State(object):
def __init__(self,**kwargs):
self.__dict__.update(kwargs)

myState1 = State(Fire=10, Earth=4)
myState2 = State(Fire=20, Earth=24)

print myState1.Fire
print myState2.Earth

-- Paul
Jan 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.