# HG changeset patch # User Tassilo Philipp # Date 1612296461 -3600 # Node ID 16151547265e854dcfb5dd899caae8664858c6ed # Parent 2e8a56976bf8a6bab8637354dcf243bf318ac600 made callback example python 2 compatible, and added some randomness to numbers to sort diff -r 2e8a56976bf8 -r 16151547265e python/pydc/examples/callback.py --- a/python/pydc/examples/callback.py Tue Feb 02 20:56:54 2021 +0100 +++ b/python/pydc/examples/callback.py Tue Feb 02 21:07:41 2021 +0100 @@ -9,6 +9,7 @@ from pydc import * import sys import platform +import random import struct if sys.platform == "win32": @@ -30,8 +31,9 @@ -nums = bytearray(struct.pack("i"*8, 12, 3, 5, 99, 3, -9, -9, 0)) -es = int(len(nums)/8) # element size +n = 8 +nums = bytearray(struct.pack("i"*n, *[random.randrange (-10, 50) for i in range (n)])) +es = int(len(nums)/n) # element size def compar(a, b): @@ -46,12 +48,12 @@ # -------- -print(*struct.unpack("i"*8, nums)) +print('%d '*n % struct.unpack("i"*n, nums)) print('... qsort ...') -call(fp_qsort,"piip)v", nums, 8, es, cb) +call(fp_qsort,"piip)v", nums, n, es, cb) -print(*struct.unpack("i"*8, nums)) +print('%d '*n % struct.unpack("i"*n, nums)) free_callback(cb)