Problem: How to get an object on inactive layer with python?

i want to get an object with python on an inactive layer.

i use something like this:
object =
but for me this only works when the object is on a active layer

if the object is not on the active layer, i get an IndexError

How can i solve this?? will work no matter what layer the object is on.

i think i know the reason for the error, when the object is on an inactive layer.

i want to copy/duplicate an object and for this i select it with python
after i selected it, i duplicate it and the next step is to get the last added object (i check the selected object then, because the last added gets selected when i duplicated it.

how do you duplicte?

i select it before

piece of code:
bpy.ops.object.select_all(action=‘DESELECT’) (deselect all)

               = True (select the object i want to copy)


i tested it, but i don’t know if i can copy an object without selecting it before and for me duplicating does not work when the object is not on the active layer

my (dirty) solution was to move the object to copy on an active layer and then move back to the first one. there is only the problem when in local view, i have to put them into the local view-mode too.