socket script from perl -> python

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Feb 8 06:59:11 EST 2008


Hrvoje Niksic  <hniksic at xemacs.org> wrote:
>kettle <Josef.Robert.Novak at gmail.com> writes:
>> # pack $length as a 32-bit network-independent long
>> my $len = pack('N', $length);
>[...]
>> the sticking point seems to be the $len variable.
>Use len = struct.pack('!L', length) in Python.  See
>http://docs.python.org/lib/module-struct.html for details.

Don't use "len = ..." -- shadowing the builtin "len" is asking for
trouble. The OP actually avoided this pitfall in his attempt at a
Python solution, translating "$len" to "leng".

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list