A simple array in Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bg_ie@yahoo.com

    #1

    A simple array in Python

    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.

  • Laszlo Nagy

    #2
    Re: A simple array in Python

    bg_ie@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

    myState[State.Fire] = 20
    myState[State.Earth] = 24
    print myState

    {0: 20, 2: 24}


    Comment

    • Paul McGuire

      #3
      Re: A simple array in Python

      <bg_ie@yahoo.co mwrote in message
      news:1168337391 .770307.54750@1 1g2000cwr.googl egroups.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__.u pdate(kwargs)

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

      print myState1.Fire
      print myState2.Earth

      -- Paul


      Comment

      Working...