473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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.

Jan 9 '07 #1
2 1460
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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JW | last post by:
Hi, Below is a description of what I would like to do. Would someone tell me if it is possible and if so, how? I have an array (presumably 'large') that is mallocced in a C function and its...
20
by: Matthew Thorley | last post by:
My friend sent me an email asking this: > I'm attemtping to decide which scripting language I should master and > was wondering if it's possible to do > these unixy awkish commands in python:...
8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res =...
38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
3
by: TPJ | last post by:
"The advantage of xrange() over range() is minimal (since xrange() still has to create the values when asked for them) except when a very large range is used on a memory-starved machine or when all...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
13
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python...
2
by: Rich | last post by:
I need to pass an array from C# to a managed C++ function (that will in turn call unmanaged C code). My knowledge of managed C++ syntax is limited (obviously). This needs to be a reference...
5
by: shashi59 | last post by:
Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
6
by: Eric | last post by:
I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.