piping out binaries properly
Paul Watson
pwatson at redlinepy.com
Wed Oct 12 16:39:33 EDT 2005
"Andy Leszczynski" <leszczynscyATnospam.yahoo.com.nospam> wrote in message
news:o_2dnb6i-uyI69HeRVn-rg at comcast.com...
>I have got following program:
>
> import sys
> import binascii
> from string import *
> sys.stdout.write(binascii.unhexlify("41410A4141"))
>
>
> when I run under Unix I got:
>
> $ python u.py > u.bin
> $ od -t x1 u.bin
> 0000000 41 41 0a 41 41
>
> and under Windows/Cygwin following:
>
> $ python u.py > u.bin
> $ od -t x1 u.bin
> 0000000 41 41 0d 0a 41 41
> 0000006
>
>
> The question is how can I pipe out binary content properly and platform
> independently?
>
>
> A.
try:
import msvcrt, os
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
except:
pass
More information about the Python-list
mailing list