06-23-2009, 04:25 PM
|
#2 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
I can try:
python Code:
def replaceWith(self, replaceWith):
#store old parent oldParent = self.parent
#get own index in parents contents array myIndex = self.parent.contents.index(self)
# if mine and replaceWith's parent is same if hasattr(replaceWith, 'parent') and replaceWith.parent == self.parent:
# We're replacing this element with one of its siblings. index = self.parent.contents.index(replaceWith) if index and index < myIndex:
# Furthermore, it comes before this element. That # means that when we extract it, the index of this # element will change. myIndex = myIndex - 1
"hasattr(object, name)
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an exception or not.)"
So we are just looking to see if an object is viable.
Hmm, I'm stuck (I have very little experience with python), but it looks like your trying to replace objects.
If you had more code or documentation on this it would help.
|
|
|
|