[Python-au] Python Sockets

Andy Dent dent@oofile.com.au
Thu, 23 Jan 2003 02:54:08 +0800


At 16:41 +1100 22/01/2003, Garth Kidd wrote:
At 13:01 +0800 22/01/2003, Andy Dent wrote:
>>        while lastI>1 and not inStr[lastI-1]==">":
>>            lastI-=1
>>        inStr = inStr[0:lastI]

>``rfind`` to the rescue::
>
>    def recvCleanPacket(self, numBytes):
>        "use instead of just using recv"
>        inStr=self.request.recv(numBytes)
>        if inStr and inStr[-1:] != '>':
>            return inStr[:inStr.rfind('>')+1]

or
>        return inStr[:inStr.rfind('>')+1]

Thanks Garth - the original loop is part of debugging code and had print
statements in there to tell me what garbage was being included but it's
nice to be educated on the finer points of Pythoneering - I'm still
learning some of the libraries and idioms.
-- 
Andy Dent BSc  MACS  AACM   http://www.oofile.com.au/
OOFILE - Database, Reports, Graphs, GUI for c++ on Mac, Unix & Windows
PP2MFC - PowerPlant->MFC portability