[Chicago] Python/Mono slapdown [no pycon content]

Martin Maney maney at two14.net
Fri Mar 7 03:15:19 CET 2008


On Thu, Mar 06, 2008 at 05:38:37PM -0600, Ian Bicking wrote:
> It's basically for holding lots of data and handling it efficiently. 
> It's used a lot by PyGame, for instance, because things like bitmaps fit 
> that model.  Anytime you have to efficiently handle lots of numeric data 
> (including bytes and ints) it is handy, as it stores them efficiently 
> and only turns them into Python objects on demand.

Since you already know all about it, I'm gonna ask you rather than
digging it up myself: does this stretch to cover things less homogenous
than arrays?  Or, as would often be the case I think, arrays of binary
structs - still a fixed layout, say, but not just X integers, all
alike.

> I also think with buffer or array, and the struct module, you can do 
> this on your own.

But again, if the app's main, large data store is this big array of
binary structs, then a more C-like view of data (as I believe C# has)
will have a better match to it.  And I'm not saying that to argue that
Python ought to have a more C-like data model, just that it's IMO well
chosen level of abstraction inherently makes it less convenient to deal
with this sort of structured binary data.  I prefer that tradeoff the
way it is, but I don't seem to deal with that sort of binary blob much.

> The one on pypi: http://pypi.python.org/pypi/enum/0.4.3

Finney's enum.  Saw that one, did think it looked like the most ready
for use... but it also looks rather heavyweight (from the point of view
of a hardcore C hacker, a role I can still remember well enough to fake
sometimes) if all one really wants is to get a sequence of integer
values bound to a specified set of names...  something I may need to do
for pyncp fairly soon, come to think of it.

I really don't see that the x,y,z = range(n) is any worse a kluge than,
say the traditional  x and True or False  substitute for the ternary
operator, and that was viscously defended as The One Way on c.l.p for
years despite it's obvious fragility and unintuitive form.  BTW, I was
happy today to "discover" a replacement for that specific usage (taking
an arbitrary Python object and converting it to 1 or 0 as it evaluates
to true or false in Python).  int(bool(x))  works just fine, for
sufficently recent versions (I'm pretty sure it wasn't an available
option when I started, using 1.5.something - amazing how much trouble I
have remembering some of the features added since then if they're not
ones I use often, especially when they replaced a well-worn idiom).

... okay, except that it does require you to keep the list and n in
sync, but it gives a clear and immediate error at the least hint of any
sort of testing if you didn't, so it's pretty innocuous.

-- 
Here's my message to the record industry and its allies:
I'm not a thief.  I'm a customer.  When you treat me like a
thief, I won't be your customer.  -- Dan Gillmor



More information about the Chicago mailing list