changeset 56:16151547265e

made callback example python 2 compatible, and added some randomness to numbers to sort
author Tassilo Philipp
date Tue, 02 Feb 2021 21:07:41 +0100
parents 2e8a56976bf8
children 80b11152c659
files python/pydc/examples/callback.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)