How to make a object create another object
As in the title how do I go about creating a object which creates another object? The object is simply supposed to 开发者_如何学Creplicate itself so like I call on this class to replicate itself the objects don't have to be different just that it creates another one of itself in like a endless loop. The grey goo example is basically what I want.
class foo(object):
def make_object(self):
return []
f = foo()
myobject = f.make_object()
This object creates another object (an empty list) and returns it.
But I have a feeling this is not what you intended. You need to specify more in your question and explain what specifically you are having trouble with. The snippet above is a trivial example that shows how easy it is to satisfy your question (it could have actually been shorter).
UPDATE
Here is the example slightly modified, just to show you how you can create an object of the same type
class foo(object):
def make_object(self):
return foo()
f = foo()
myobject = f.make_object()
精彩评论