As scuba111223 say, the near sensor have a attribute, the “hitObject” returns a KX_GameObject of the object that activate the sensor, so you can use it:
if near.hitObject:
object = near.hitObject
#Example
object.setParent("other_object") #You can use directly a KX_GameObject
cont.activate("attack") #the activate function also accept a string.