![]() |
PROBLEM IN writing code
dear all..
I wanted to write some code which is already in python..but as i m very new in php not able find which function like hasattr i have to use at that place.can anyone tell me how to write this code in php... python code is.. 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 |
I can try:
python Code:
"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. |
I think he wants that Python code written into PHP. Hence why I soon closed the thread :-) But at least the code now makes more sense since you've written it up.
|
Quote:
|
| All times are GMT. The time now is 08:44 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0