On Wed, Feb 6, 2013 at 1:55 PM, Buck Calabro <kc2hiz@xxxxxxxxx> wrote:
I'm not a Python programmer as much as a Python dabbler.
Nothing wrong with dabbling. Python is one of the easier languages to
be productive with at the dabble level. Dabble long enough and before
you know it, you're an intermediate Python programmer. ;)
I recently discovered named tuples
http://docs.python.org/2/library/collections.html and it seems that this
is the way to emulate the C structs that various IBM APIs return data
with. It doesn't matter to me that they're immutable, as I'm going to
want to read them, not update them.
When you need to work with C structs, what you want in Python is the
This module lets you pack Python values into a struct or unpack a
struct into a tuple of Python values. (If you like, you can then use
this tuple to build a named tuple.)
Traversing the list of columns
returned (QUSLFLD) seems harder to me though. I so want to use
pointers! Not looking for code, just musing aloud. No time to try it
now though :-(
For the particular case of QUSLFLD, the main problem is that the
results are not in the parameters but in a user space. (Disclosure:
I have never personally used this API, and am going by the Web docs.)
Unfortunately, iSeries Python doesn't have a convenient way of
accessing user spaces, that I know of. Someone had built one for an
older version of Python, running on V5R2, using various APIs; but
predictably, this can't be used for today's Python on today's i.
Right now, iSeries Python really needs data to be passed around in
parameters, files (database or IFS), or data areas. So your original
thought of an RPG wrapper/helper might not have been too far off the
mark after all.
For the very specific case of getting buffer lengths for fields, well,
that's already built into iSeries Python's File400 class, so no need
for QUSLFLD or DSPFFD or anything else. Example (not that you were
f = File400('MYFILE', lib='MYLIB')
for field in f.fieldList():
print field, f.fieldSize(field)
That will print out a list of all the fields in MYLIB/MYFILE, along
with their buffer sizes.