Structures
Paulo J. Matos
pocmatos at gmail.com
Mon Nov 3 18:32:25 EST 2008
On Mon, Nov 3, 2008 at 10:10 PM, Arnaud Delobelle
<arnodel at googlemail.com> wrote:
> Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
>
>> "Paulo J. Matos" <pocmatos at gmail.com> writes:
> [...]
>> Okay, you're talking about 'struct' from the C language. That helps
>> answer the question.
>
> Note that structs are mutable.
>
Ah... :( That's a no go!
>> In Python, the way to do that is with a dict. A class can be used, but
>> is often overkill if one doesn't need customised behaviour.
>>
>>> The fact that python 2.6 has now named tuples is a breath of fresh
>>> air!
>
> But isn't mutable, so it doesn't seem to be what you (Paulo) need.
>
What's then the reason for adding named tuples if they are not mutable...???
>> That works also, but a dict will be more broadly useful; and
>> compatible with any Python version.
>
> And is mutable.
>
Even though I can use dicts where the keys are strings (as if it were
the name of the field), it seems to heavy, since a structure doesn't
need to be resizable (and dicts are) and it has constant time access
(which depending on the implementation I would guess dicts don't
have).
Can someone please clarify?
Cheers,
Paulo
> --
> Arnaud
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
--
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm
More information about the Python-list
mailing list