name depending on the position on a line
Sorting by z and x location

Simple script to sort all the objects in a scene named "Cube[.nnn]" by -z location and x location.  Added a tolerance of 0.0001, any cube with a z within is considered in same row.  The .nnn extension is the index in the order. 

import bpy

context = bpy.context
scene = context.scene
# all cubes in the scene
cubes = [o for o in scene.objects if o.name.startswith("Cube")]
# row tolerance
TOL = 0.0001
if cubes:
    #sort them by -z , x loc
    cubes  = sorted(cubes, key = lambda o: (-o.location.z, o.location.x))
    row = 1
    z = cubes[0].location.z
    for i, cube in enumerate(cubes):
        if abs(cube.location.z - z) &gt; TOL:
            row += 1
            z = cube.location.z
        cube.name = "Cube_%d.%03d" % (row, i)


To name them similarly to the convention in the q, could  

cube.name = cube.name.replace("Cube", "Cube_%d" % row)


To make sure global locations are used, use cube.matrix_world.to_translation() instead of cube.location.

Or if the objects have differing origins, could use the bounding box centre as a location.