So I am pretty new to python so be kind. I am trying to create a global sort of object directory as a base for all my programs as a means to keep track of all created object instances in my programs.
so..
I create a class that holds a list of object references ( not id's ). example:
class objDirectory:
name = ""
count = 0
objDir = []
def __init__( self ):
print( "Initiating object directory." )
name = "objDirectory"
self.count= 1
self.objDir = [ self ]
return
def getObj( self, name ):
print( "Searching directory for:", name )
for o in self.objDir:
if o.name is name:
print( "Returning:", name )
return obj
else:
print( "Search failed" )
return
But, once an object is added to a list and I run the get script it does not return my object. I even verify by using directory.objDir[x]. ( this always references my object) .
What am I not doing, or doing wrong?
Thanks.
Results:
setDirectory() Initiating object directory. Global directory reference set test = obj( "test" ) Initiating: test Duplicate check Logging: test1 Object count: 2 t1 = directory.getObj( "test1" ) Searching directory for: test1 Search failed print( directory.objDir ) [<main.objDirectory object at 0x032C86F0>, <main.obj object at 0x032C8710>]