[Python-ideas] Python Users Aren't Perfect
mwm at mired.org
Fri Dec 16 05:34:28 CET 2011
On Thu, 15 Dec 2011 16:54:16 -0500
Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 12/15/2011 4:24 PM, Ethan Furman wrote:
> > Python is a dynamic language -- why can't it have dynamic structs?
> I honestly don't know how to interpret this.
I do. Ethan is incorrectly trying to turn a similarity - that both
Python tuples and C structs are collections of heterogeneous data -
into an analogy. They aren't analogs, as that's pretty much the only
If you really want a dynamic tuple - a dynamic collection of
heterogeneous data accessed by an index - use a list. That was
standard practice in LISP-like languages for a long time. But Python
(and most modern LISPs) has better tools for such.
For instance, the proper analog for a C struct in Python is the
class. You provide definitions of them both along with names for their
heterogeneous components. You create instances of them both that can
assign different values to those components. The components are
properly accessed by name. There are probably other similarities.
There are a number of differences as well. Most notably, instances of
classes are dynamic. You can change, and even add and delete,
So Python already has a dynamic struct. You just have to get the
Mike Meyer <mwm at mired.org> http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the Python-ideas