Using object's printed name in script I am trying to write a script that will end up baking materials from a high poly object to a low poly object. The problem i am having is that i will never know the object names beforehand, as my script is importing obj's from a folder into blender then duplicating them and applying a decimate filter to them. So far i have all of that functioning correctly, but i'm stuck on the final part of selecting the low poly at the target object of the bake. 

&gt;&gt;&gt; bpy.ops.object.select_by_type(type='MESH')
{'FINISHED'}

&gt;&gt;&gt; 
&gt;&gt;&gt; for obj in bpy.context.scene.objects:
...     if obj.name.endswith("001"):
...         print(ob.name)
...         bpy.context.view_layer.objects.active = ob
...         
Hat 1.001

&gt;&gt;&gt; 


I have the script printing out the name of the object that has a name ending in 001 since i know that my low poly duplicate will always end with that. My problem is that i need to take that printed name and apply it to the next command like this example

bpy.context.scene.targetobj = "Hat 1.001"


I can't figure out how to take the name that gets printed out and apply it like in that example. Thanks in advance.
Use a pointer property

Can set up a pointer to any blender ID type objects, in this case bpy.types.Object instances of which can be found in bpy.data.objects collection.

Assign the property to class

import bpy
from bpy.types import Object, Scene
from bpy.props import PointerProperty


Scene.target_obj = PointerProperty(type=Object)


Test.

&gt;&gt;&gt; C.object
bpy.data.objects['Cube']

&gt;&gt;&gt; bpy.ops.object.duplicate()
{'FINISHED'}

&gt;&gt;&gt; C.object
bpy.data.objects['Cube.001']

&gt;&gt;&gt; C.scene.target_obj = C.object
&gt;&gt;&gt; C.object.name = "Foo"
&gt;&gt;&gt; C.scene.target_obj
bpy.data.objects['Foo']