Python wish list

Apr 14, 2011 17:34

Now that the moratorium on Python language features is over, I'll put in my thoughts on what new stuff the language could use. I don't have much to suggest, and what I do have to suggest is fairly minor. This is because I'm happy with the language.

new on default parameters

One of the gotchas in python is that default parameters are reused, so if ( Read more... )

Leave a comment

ext_439117 April 15 2011, 03:28:31 UTC
It sounds like the struct module should do what you want for raw binary conversion.

Since the dictionary objects are only kept in the hash table and iteration just walks through that table looking for objects, there'd be no way to scramble the contents in-place. Objects can only be in one place for a given hash value. You'd have to implement this by iterating the dictionary into a list and shuffling that list in place (like random.shuffle does), so you might as well do it yourself.

^ on bytes is an obvious feature, though, you're absolutely right. I might actually write a patch for that myself...

Reply

bramcohen April 15 2011, 05:11:05 UTC
Just changing the hash function which dicts use should scramble things well enough.

Does struct work on arbitrary size integers and allow completely cross-platform operation? The documentation is less than ideal.

Reply

manuzhai April 15 2011, 07:21:45 UTC
The table for the format characters seems clear enough?

Reply

bramcohen April 15 2011, 16:32:52 UTC
Until you've gone through some examples, it's very opaque, and it really, really, would be nice if it clarified whether int sizes might be different on different platforms.

Reply

elsmi April 15 2011, 18:46:25 UTC
The docs really could be better (I use struct constantly, and it took me ages to realize that you can give a repetition count like "<4I"), but at least the current docs do say explicitly that if you use the 'native mode' indicator ("@", which is default), then you get whatever sizes and alignment the C compiler would use for a C struct with the given fields, and if you use one of the standardized modes ("<", ">", "=", "!") then you get the usual int sizes (and no padding) regardless of platform. So "@" is how you talk to poorly-written C code, and for network protocols or well-written binary formats you use "<" or ">".

Reply


Leave a comment

Up