Martin v. Löwis <martin <at> v.loewis.de> writes: > > Bill Baxter schrieb: > > Basically in my code I want to be able to take the binary data descriptor > > and > > say "give me the 'r' field of this pixel as an integer". > > > > Is either one (the PEP or c-types) clearly easier to use in this case? > > What > > would the code look like for handling both formats generically? > > The PEP, as specified, does not support accessing individual fields from > Python. OTOH, ctypes, as implemented, does. This comparison is not fair, > though: an *implementation* of the PEP (say, NumPy) might also give you > Python-level access to the fields.
I see. So at the Python-user convenience level it's pretty much a wash. Are there significant differences in memory usage and/or performance? ctypes sounds to be more heavyweight from the discussion. If I have a lot of image formats I want to support is that going to mean lots of overhead with ctypes? Do I pay for it whether or not I actually end up having to handle an image in a given format? > With the PEP, you can get access to the 'r' field from C code. > Performing this access is quite tedious; as I'm uncertain whether you > actually wanted to see C code, I refrain from trying to formulate it. Actually this is more what I was after. I've written C code to interface with Numpy arrays and found it to be not so bad. But the data I was passing around was just a plain N-dimensional array of doubles. Very basic. It *sounds* like what Travis is saying is that handling a less simple case, like the one above of supporting a variety of RGB image formats, would be easier with the PEP than with ctypes. Or maybe it's generating the data in my C code that's trickier, as opposed to consuming it? I'm just trying to understand what the deal is, and at the same time perhaps inject a more concrete example into the discussion. Travis has said several times that working with ctypes, which requires a Python type per 'element', is more complicated from the C side, and I'd like to see more concretely how so, as someone who may end up needing to write such code. And I'm ok without seeing the actual code if someone can actually answer my question. The question is not whether it is tedious or not -- everything about the Python C API is tedious from what I've seen. The question is which is *more* tedious, and how significan is the difference in tediousness to the guy who's job it is to actually write the code. --bb _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com