Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Writing binary to stdout
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Paul Watson, post: 1765414"] The following appears to work under 2.1 in Cygwin and 2.3.4 under a DOS box. I did not change any Cygwin setting. Is there anything undesireable in the code below? The intent is to say if this is running on Windows, set stdout to binary mode. Am I safe in assuming that 'import msvcrt' will fail on all other machines? Is there a better way? $ cat ./wb.py #! /usr/bin/env python import sys import os try: import msvcrt msvcrt.setmode(1, os.O_BINARY) except: pass sys.stdout.write("now\n") print "and then" $ ./wb.py >jjj $ od -c jjj 000000 6e 6f 77 0a 61 6e 64 20 74 68 65 6e 0a n o w \n a n d t h e n \n 00000d [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Writing binary to stdout
Top