Change bezier curve code for upbge

I found how to get points from a spline bezier or poly curve, but how to adapt it for Upbge game object controller ?

from mathutils import geometry

count = 16
ops_mesh = ops.mesh

Create curve and randomize its points.

ops.curve.primitive_bezier_curve_add(enter_editmode=True)
ops.transform.vertex_random(offset=1.0, uniform=0.1, normal=0.01, seed=0)
ops.object.mode_set(mode=‘OBJECT’)

Acquire a reference to the bezier points.

bez_curve = context.active_object
bez_points = bez_curve.data.splines[0].bezier_points

Get a list of points distributed along the curve.

points_on_curve = geometry.interpolate_bezier(
bez_points[0].co,
bez_points[0].handle_right,
bez_points[1].handle_left,
bez_points[1].co,
count)

Create an empty object to serve as parent to all cubes.

ops.object.empty_add(type=‘PLAIN_AXES’, location=bez_curve.location)
group = context.active_object

Create cubes.

cube_rad = 0.5 / count
for point in points_on_curve:
ops_mesh.primitive_cube_add(radius=cube_rad, location=point)
cube = context.active_object
cube.parent = group

From
https://medium.com/@behreajj/scripting-curves-in-blender-with-python-c487097efd13

How to use curve or path points in Upbge :

bez_curve = bpy.data.objects[‘name_of_curve’]
bez_points = bez_curve.data.splines[0].bezier_points

index = 0
for point in bez_points :
index += 1
print(index)
print(point.co)

You can also read handle positions if needed :
point.handle_left
point.handle_right