Trouble Copying Animation

I have 2 cubes created on the stage one with animation curves
and one without. The code below should copy the keyframes from the
animated cube to the unanimated cube. Before running the script the code requires
to select the animated cube, then shift select the target cube. So I did that and ran the script and all I get are copied keys on the new cube, but the cube doesn’t animate. ???

def getAttName ( fullname) : 
     parts = fullname.split('.')
     return parts[-1]

def copyKeyframes() :
    objs = = True)

    if (len(objs) < 2):
      cmds.error('Please select at least two objects')

    sourceObj = objs[0]

    animAttributes = cmds.listAnimatable(sourceObj)
    for attribute in animAttributes:
        numKeyframes = cmds.keyframe(attribute, query = True,
        keyframeCount = True)

    if (numKeyframes > 0) :

        for obj in objs[1:] :
        attribute = getAttName(attribute), option = 'replace')


Main issue I see is your numKeyframes check is not in the for loop so only the last attr will be copied.

That was it exactly, formatting so important !
Thank you.