Generating data types automatically
Torsten Bronger
bronger at physik.rwth-aachen.de
Sat Mar 12 12:59:44 EST 2005
Hallöchen!
Torsten Bronger <bronger at physik.rwth-aachen.de> writes:
> I have to generate a lot of data types (for ctypes by the way).
> An example is
>
> ViUInt32 = u_long
> ViPUInt32 = POINTER(ViUInt32)
> ViAUInt32 = ViPUInt32
>
> Therefore, I defined functions that should make my life easier:
>
> [...]
>
> However, this doesn't work, probably because the defined type
> exist only locally within the function.
Okay this works:
def generate_type_dublett(visa_type, ctypes_type):
return visa_type + "=" + ctypes_type + ";" + \
"ViP" + visa_type[2:] + "=POINTER(" + visa_type + ")"
def generate_type_triplett(visa_type, ctypes_type):
return generate_type_dublett(visa_type, ctypes_type) + ";" + \
"ViA" + visa_type[2:] + "=" + "ViP" + visa_type[2:]
exec generate_type_triplett("ViUInt32", "c_ulong" )
...
Not very beautiful, though.
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus
More information about the Python-list
mailing list