Structures

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Nov 4 09:46:36 CET 2008


Paulo J. Matos a écrit :
(snip)

> However, I wouldn't dare to say Python needs structures to be a good
> language, or anything similar. My question was more directed to : if
> there aren't structures in Python, what do Pythonists use instead?
> (I have seen dicts might be an alternative,

Yes, and the most obvious one - at least when all you need is a kind of 
data transfert object. Else, well, C++ structs are just a survival of a 
C feature kept for compatibility reasons - technically speaking, you 
just don't need structs when you have classes.

> but as I said in previous
> post, they seem to flexible [making them a canon to shoot a fly,

Err... I'm afraid you'll find Python way to flexible and dangerous, 
then. You may not be aware of the fact that you can add / remove / 
replace objects attributes (and methods) at runtime ? FWIW, and a couple 
corner cases set asides, Python objects are mostly glorified dicts.

> and
> they probably lack constant-time access, right?]

AFAIK, it's almost constant-time access. But you won't get anything 
better using classes, since attributes are stored in a dict anyway.




More information about the Python-list mailing list