Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.05; '(it': 0.09; '22,': 0.09; 'snippet': 0.09; 'bug': 0.10; 'subject:not': 0.11; 'devs': 0.16; 'fix,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inclined': 0.16; 'reproduce': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'copied': 0.17; 'specify': 0.17; 'feb': 0.19; '2.x': 0.22; 'patch': 0.24; 'header:In-Reply- To:1': 0.25; 'looks': 0.26; 'subject:skip:d 10': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; 'mode.': 0.29; 'probably': 0.29; "i'm": 0.29; 'fri,': 0.30; 'mode': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'docs': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'jason': 0.35; 'open': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; 'url:library': 0.36; 'thank': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'easy': 0.60; 'skip:n 10': 0.63; 'love': 0.63; '2013': 0.84; 'subject:skip:N 10': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=iw6ywOzeQfhVaoDLGC9ZVLs+IWSeKh/6e0ETBoMTrsM=; b=QfIFu//cnDKLVhFTZz+hiEegWhRMnWgYmrAQMvA7SGEKBne8psUHI5FBMbwNX6Pw0s cd4ldkWZb5ZVBrIyZQg/d9R4/nyfbxHHUNHTm8HZYZ4cq4ha0P8Ehx5v/c3RINpJ358J +sR9At+829Za8OoZNYr+000zjwkJk2cfoV2fz79EFhDKLTlmwQzq8+h5yNlUrY7JfqyQ Lp/bt6Uf0r/LAm/C+nv9nGA+2aYrKi10944OwCoBwAWY4v/bHW0VLDKceA2A8nQPpDwe 5ljwKK9CKCQW3b/1fnNZ6d7ts6DAFgYJffBPquCJxFBGRiT27nLjxfrFmuhikj56rRxF LAdg== MIME-Version: 1.0 X-Received: by 10.220.219.77 with SMTP id ht13mr366815vcb.66.1361500925090; Thu, 21 Feb 2013 18:42:05 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Feb 2013 13:42:04 +1100 Subject: Re: NamedTemporaryFile does not match documentation 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361500927 news.xs4all.nl 6899 [2001:888:2000:d::a6]:34064 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39516 On Fri, Feb 22, 2013 at 1:10 PM, Jason Friedman wrote: >> NamedTemporaryFile by default opens a file in binary mode ('w+b'). Write >> bytes or specify text mode. >> >>>>> f.write(b"Hello World!\n") >> 13 >>>>> ft = NamedTemporaryFile('w+', delete=False) >>>>> ft.write("Hello World!\n") >> 13 > > Thank you Chris and Serhiy, that helped. I'm inclined to open a > documentation bug because I could not reproduce the code/output > snippet on page > http://docs.python.org/release/3.2.2/library/tempfile.html#module-tempfile. Yep, that looks like a docs bug (it was probably copied straight in from the 2.x docs). Nice and easy to fix, you could submit a patch with the bug report and make the devs love you! ChrisA