Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39464
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tempfile': 0.09; 'typeerror:': 0.09; 'subject:not': 0.11; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'writer': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'specify': 0.17; '>>>': 0.18; 'feb': 0.19; 'import': 0.21; '"",': 0.22; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'subject:skip:d 10': 0.27; 'interface': 0.27; 'header:X -Complaints-To:1': 0.28; 'lines': 0.28; '>>>>': 0.29; 'mode.': 0.29; 'maybe': 0.29; "skip:' 10": 0.30; 'mode': 0.30; 'file': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'or,': 0.34; 'along': 0.35; 'jason': 0.35; 'received:org': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'skip:n 10': 0.63; 'more': 0.63; 'skip:n 30': 0.69; 'goal': 0.74; 'subject:skip:N 10': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Serhiy Storchaka <storchaka@gmail.com> |
| Subject | Re: NamedTemporaryFile does not match documentation |
| Date | Thu, 21 Feb 2013 23:30:00 +0200 |
| References | <CANy1k1g4eJ+9aBArQm_r8k0iKKuaxf_wzKjdEjOkj7M0J7=N8A@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 94.153.171.207 |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| In-Reply-To | <CANy1k1g4eJ+9aBArQm_r8k0iKKuaxf_wzKjdEjOkj7M0J7=N8A@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2200.1361482221.2939.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1361482221 news.xs4all.nl 6862 [2001:888:2000:d::a6]:46736 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:39464 |
Show key headers only | View raw
On 21.02.13 22:46, Jason Friedman wrote:
> Python 3.2.2 (default, Feb 14 2012, 08:06:31)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from tempfile import NamedTemporaryFile
>>>> f = NamedTemporaryFile(delete=False)
>>>> f
> <tempfile._TemporaryFileWrapper object at 0x7f867e8bc050>
>>>> f.name
> '/tmp/tmpqxnd_4'
>>>> f.write("Hello World!\n")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'str' does not support the buffer interface
>
> Or, maybe I am reading the documentation incorrectly. My goal is to
> be able to write to that temporary file along the lines of "f.write()"
> or "with open(f) as writer ...".
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: NamedTemporaryFile does not match documentation Serhiy Storchaka <storchaka@gmail.com> - 2013-02-21 23:30 +0200
csiph-web