socket script from perl -> python

Jerry Hill malaclypse2 at gmail.com
Thu Feb 7 10:40:25 EST 2008


On Feb 7, 2008 9:39 AM, kettle <Josef.Robert.Novak at gmail.com> wrote:
> f = open('/home/myuname/socket.wav','rb')
> audio = ""
> for line in f:
>     audio += line

I don't know anything about socket programming in python, but this bit
doesn't seem right for working on a binary file.  You should just read
all of the data into audio in one go, like this:

f = open('/home/myuname/socket.wav','rb')
audio = f.read()

There's no need to iterate over the lines in the file, since it's
quite likely that there really aren't any 'lines' in a binary file.

-- 
Jerry



More information about the Python-list mailing list