3 ms·
Disappointed that my favorite pythonic pattern of "here's a dict with unknown contents, do the right thing with it" is not listed.
by photios 1y ago
Disappointed that my favorite pythonic pattern of "here's a dict with unknown contents, do the right thing with it" is not listed.
- sunrunner 1y agoHey now, at least the dictionary has keys that _could_ hint at the contents (or be completely misleading). What about the tuple with just positions? image.size ndarray.shape Are the image sizes (width, height) or (height, width)? Trick question of course, it's (height, width, channels) for numpy. numpy is fairly well known though and sort of gets away with it, but when your never-seen-before internal company starts doing this, well...
- vidyava 1y agoSerious question, but what is the best practice for keeping n-dimensional arrays organized/labeled? Pandas? Xarray? Converting everything to netcdf before using it?
- msgodel 1y agoIt's not just Python. You see this a lot in Javascript and Groovy too. Really I think what makes languages with manual memory management and limited built in types like C nice is it forces people to really think about the types and interfaces they're writing instead of just hacking unmaintainable code at 20 lines an hour.
- alfons_foobar 1y agoWhat do you mean, "unknown contents"? Just trace back the dict to it's origin, through all the places it can be modified, and you know what is (or could be) inside... /s
- naveed125 1y agohaha, i should add this.
- ck45 1y agoSeen (and fixed): A function returns some “struct” (as a dict), with a couple of fields, mostly stringly typed, and one field for accumulating error messages called “errors”. The dict was created as a defaultdict(list) (probably) to make it easier to append messages.