TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-23-2009, 10:27 AM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default 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
tech is offline  
Reply With Quote
Old 06-23-2009, 04:25 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

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.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 06-23-2009, 04:48 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-23-2009, 05:04 PM   #4 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
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.
I know that he wants the python to be rewritten into PHP, but I was asking for more details on/with the python code.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 45 12-03-2012 07:46 AM
Writing Clean Code Village Idiot Tips & Tricks 10 06-25-2012 12:35 PM
Problem with Code Igniter URLs ETbyrne General 2 11-11-2008 01:00 AM
Problem with code in PHP file lashawnie Javascript, AJAX, E4X 2 12-06-2007 06:33 AM
Problem with code /\/\ongoose General 22 11-06-2007 12:00 PM


All times are GMT. The time now is 07:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design