syntax for code blocks

Kiuhnm kiuhnm03.4t.yahoo.it
Mon Apr 30 11:24:09 EDT 2012


On 4/30/2012 17:02, Kiuhnm wrote:
> On 4/30/2012 16:17, mwilson at the-wire.com wrote:
>> Ben Finney wrote:
>>
>>> [ ... ] Even worse is the
>>> penchant for ‘foo .bar()’, the space obscures the fact that this is
>>> attribute access.
>>
>> I like the style sometimes when it helps to break the significantly
>> different parts out of
>> boilerplate:
>>
>> libbnem. BN_add .argtypes = [ctypes.POINTER (BignumType),
>> ctypes.POINTER (BignumType),
>> ctypes.POINTER (BignumType)]
>> libbnem. BN_add .restype = ctypes.c_int
>> libbnem. BN_add_word .argtypes = [ctypes.POINTER (BignumType),
>> ctypes.c_ulong]
>> libbnem. BN_add_word .restype = ctypes.c_int
>>
>> libbnem. BN_sub .argtypes = [ctypes.POINTER (BignumType),
>> ctypes.POINTER (BignumType),
>> ctypes.POINTER (BignumType)]
>> libbnem. BN_sub .restype = ctypes.c_int
>> libbnem. BN_sub_word .argtypes = [ctypes.POINTER (BignumType),
>> ctypes.c_ulong]
>> libbnem. BN_sub_word .restype = ctypes.c_int
>>
>> (there were a lot more in the original program where those came from.)
>> Another take-away
>> might be don't use boilerplate, but in the situation I didn't see a
>> simple way to avoid it.
>>
>> Mel.
>
> BignumTypePtr = ctypes.POINTER(BignumType)
>
> for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
> (libbnem.BN_sub, libbnem.BN_sub_word)):
> op.argtypes = [BignumTypePtr] * 3
> op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
> op.restype = op_word.restype = ctypes.c_int

On second thought, BignumPtrType is probably the right name.

Kiuhnm



More information about the Python-list mailing list