# Generating hooked curve through “n” number of points with python

It is possible to generate a curve in python through n number of points and the curve to be hooked to the points? Extrapolating I want to be able to generate curve through center of cubes curve that will stay hooked with the cubes so any update to the cubes will update the curve.

import bpy
from mathutils import Vector
cubes = [ob for ob in bpy.context.scene.objects if ob.name.startswith('Cube')]
spline = bpy.context.active_object
length = len(spline.data.splines[0].points)
for i in range(length):
bpy.ops.curve.select_all(action='DESELECT')
point = spline.data.splines[0].points[i]
cube = cubes[i]
point.select = True
point.co = Vector((cube.location.x, cube.location.y, cube.location.z, 1))
cube.select_set(True)