![]() |
PHP to Python?
Is there anyone that is able to convert this small php snippet
:
fputs($sock,"\\status\\"); $gotfinal=False; $data="";to Python?? I've got :
global chunksBut as you'll notice tis is not really a good match !! :( Thanks for anyone that is able to help! It would be greatly appriciated!! :banana: |
Yeah, I can convert it. Understand that there is difference between translation/transliteration and implementing a good solution. Despite your sig, "make life simple", I think you need to learn to adapt to the good life. Hanging on the sugar tit is not generally considered to qualify, pleasant and unchallenging as it might be.
|
Yeah, that code is messy and the intent is hard to follow. Use proper indentation (how did you manage not to in python?) and please explain the point of the code.
It appears to send "status\" over a socket then receive data (with some odd timeouts and sleeps thrown in) until it gets back "final\". Then it splits it based on the "\" character. This is as close as I got (untested). :
|
Firstly the first code (PHP) Is not mine, but it is what I need for the code that I am writing in python, as for the indentation comment how that is relevant to it being poorly spaced on a forum I find irellevant within my code it works.
As for my sig, I can see sarcasm is wasted to your wise wit... I came here asking for help not for a debate. Your code that you have posted is pretty much a match to mine but thanks anyway.. :) The code should be simple to understand both in the PHP and Python. It sends status to a socket, gets the data back from the socket, BUT I was hoping for a if no new data, wait and check again sort of thing, because at the moment some of the data that should be there is not! And from what I can interprit from the PHP if looks like if new data is not found it waits, then gets more, so maybe this is what my code was missing then split the data from the server in to chunks... Sorry if it sounds like I am biting back at anyone in the above, but "Hanging on the sugar tit is not generally considered to qualify" thought this was a 'Programming Forum' not a 'Lessons to Life Forum'.... :
def Update():But I am unsure if this gets all the data from the server. Cheers for anyone willing to help and not give bites... |
When I said indentation I was referring to the leaving of statements one line, no need to do so in python. It just increases the line noise to code ratio, which seemed high to my non-PHP trained eyes.
Quote:
Here is a version of the code the implements the proper waiting semantics and is well commented. :
I don't think the odd waiting code is needed, the socket timeout is should be enough. If you set the timeout to be 2 seconds the socket will block for 2 seconds to wait for new data. |
That you very much! :)
|
If you want to check whether any data can be read, the select module is what you're looking for.
|
| All times are GMT -5. The time now is 11:27 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC