Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'defaults': 0.05; 'subject:skip:s 10': 0.05; 'bytes.': 0.07; 'read-only': 0.07; 'python': 0.09; 'fails.': 0.09; 'open()': 0.09; 'sat,': 0.15; 'decode': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oct': 0.16; 'wrote:': 0.17; 'specify': 0.17; 'unicode': 0.17; '>>>': 0.18; 'otherwise,': 0.20; 'received:209.85.214.174': 0.21; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'mode.': 0.29; 'fri,': 0.30; 'mode': 0.30; 'writes': 0.30; 'file': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'returning': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'characters': 0.36; 'subject:with': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'containing': 0.61; 'subject:write': 0.84; 'dennis': 0.91; 'edwards': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=9M40mCAf7KP54z+d8qQTxKVBQ8BW60gHNaQHve+1yko=; b=lgk5oGTQXllUUlY0IK4tCvxrPZT/IyUdpk4B3E6R4wq82Y4YWg7US9ZmIZ6zdiwJJW VDPRik82fngLwFksjJlJE2aAS1KvCluQkZvfeERoJq6+xPpaeLdbnC2yTkKcoBNGC4IV uB1oWl50pKKhw7upi5H9Zpct2qyJCxE+h9lyFSKc9MoalIOTMJ6O4uJeglD8Piul3nHj TxcMDn7Zh3UPtHlrLOoCUNccNM9Vk5MF2CC3SBkPDP7ufDNkCKl3GuuPtdHS5y+Bo/mZ d9xgKrp12U8tn4EMBVvdUcETxhDKVrppsnmT+gpZcJLAW+RUJBOAMIy82tuJSSyzZbS1 3wMQ== MIME-Version: 1.0 In-Reply-To: References: <1349494056881-4991234.post@n6.nabble.com> Date: Sat, 6 Oct 2012 23:52:47 +1000 Subject: Re: write binary with struct.pack_into From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349531571 news.xs4all.nl 6964 [2001:888:2000:d::a6]:49952 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30890 On Sat, Oct 6, 2012 at 11:26 PM, Grant Edwards wrote: > On 2012-10-06, Dennis Lee Bieber wrote: >> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira >> declaimed the following in gmane.comp.python.general: >> >>> >>> #WRITE >>> fb=open('testOUT.bin') >> >> Unless you specify otherwise, open() defaults to read-only > > It also defaults to 'text' mode which does cr/lf translaction. That > will break both reads and writes on any binary file containing 0x0a > and 0x0d bytes. And, in Python 3, it'll be returning Unicode characters too, unless the decode fails. You definitely want binary mode. ChrisA