pythonic malloc
Jude Venn
jude-venn at blueyonder.co.uk
Mon Jul 21 08:42:33 EDT 2003
how about something like:
retpacket = "\xf0\x00\x02\x00"+socket.gethostname()
retpacket += chr(0) * (25 - len(retpacket))
On Mon, 21 Jul 2003 09:15:26 GMT
kjockey <kj at ockey.fake.> wrote:
> I have some simple UDP code that does:
> s.sendto("\xf0\x00\x02\x00rachel\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",addr)
>
> This is OK, except that I'd like to change the text in the middle ("rachel",
> which is the hostname FWIW), and the NUL padding needs to go out to make
> the length 25 bytes (so the padding depends on the length of the name).
>
> So I could do something like:
> retpacket = "\xf0\x00\x02\x00"+socket.gethostname()
> while len(retpacket) < 26:
> retpacket += "\x00"
> s.sendto(retpacket, addr)
>
> But that feels "wrong". And Python in a Nutshell says its a bad idea -
> "anti-idiom".
>
> Can anyone show me the true path?
>
> Brad
More information about the Python-list
mailing list