There are some possible ways to resolve this issue, it would be better to follow StackOverflow where I got the related answer, I hope it will help you a lot.
import maya.cmds as cmds
sel = cmds.ls(sl=True, fl=True)
x=1
for i in sel:
pos = cmds.pointPosition(i)
c = cmds.spaceLocator(n="loc{0}".format(x) , p=(0, 0, 0) )
x+=1
d = cmds.xform(c[0], a=True, t=(pos[0], pos[1], pos[2]) )
g = cmds.group(c, n = 'loc_grp_{0}'.format(c[0][-2:]))
dspL = cmds.createDisplayLayer( noRecurse=True, name='LocLayer_{0}'.format(c[0]))
cmds.editDisplayLayerMembers(dspL, g, noRecurse=True)
If you still don't find the answer, you must visit this link. Don't forget to follow survey login and give me a feedback over here.