How to make local objects link mantain their hierachy in Blender 2.8 python? (SOLVED) Is there a way to maintain hierarchy objects after we Make Local several linked objects the scene ?

I notice that if we try Make Local the parent object, the child will be put outside the parent, in my code example below, the last for loop was to make every objects that start with prefix "C_" will be made local, but I can't find a way how to order the loop so it would start from child to parent, instead of randomly pick the object.

import bpy

context = bpy.context
scene = context.scene

filepath = "C:/Char/C_Character.blend"

# append all objects starting with 'C_'
with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to):
    data_to.objects = [name for name in data_from.objects if name.startswith("C_")]


# link them to scene
for obj in data_to.objects:
    if obj is not None:
        scene.collection.objects.link(obj)

# make them local
for obj in scene.objects:
    if obj.name.startswith("C_"):
        obj.make_local()




Thanks a lot !
I somehow accidentally using Operator Search (F3) and type in Make Local to selected objects, and the hierarchy perfectly maintain, though using operator is not really ideal, but it works at the moment.
EDIT : Please make sure you turn off Empty and Curve object display, it need to local mesh first to mantain hierarchy

so I change the script to :

# make them local
for obj in scene.objects:
    if obj.name.startswith("C_"):
        bpy.ops.object.select_pattern(pattern='C_*')
        bpy.ops.object.make_local(type='SELECT_OBJECT')


So I hope this can be helpful

Thanks