Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28420
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subsequent': 0.04; 'subject:Python': 0.05; 'upgraded': 0.05; 'args)': 0.07; 'override': 0.07; 'parameter': 0.07; 'wrapped': 0.07; 'python': 0.09; '"w")': 0.09; 'adams': 0.09; 'alternatives': 0.09; 'blocked': 0.09; 'buffer,': 0.09; 'descriptor': 0.09; 'logic': 0.09; 'non-blocking': 0.09; 'path,': 0.09; 'read()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runtime': 0.09; 'sep': 0.09; 'spawn': 0.09; 'subclass': 0.09; 'thread': 0.11; '2.7': 0.13; 'dec': 0.15; 'buffering': 0.16; 'cleaner': 0.16; 'directly?': 0.16; 'finney': 0.16; 'low-level': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statements;': 0.16; 'string': 0.17; 'certainly': 0.17; 'implementing': 0.17; '>>>': 0.18; 'module': 0.19; 'import': 0.21; 'meant': 0.21; '(by': 0.22; 'object.': 0.22; "python's": 0.23; 'statement': 0.23; 'second': 0.24; 'object,': 0.27; 'replace': 0.27; 'regular': 0.27; "doesn't": 0.28; 'header:X-Complaints- To:1': 0.28; 'went': 0.28; 'far,': 0.29; 'i/o': 0.29; 'queue': 0.29; 'statements': 0.29; 'probably': 0.29; 'that.': 0.30; 'normally': 0.30; 'function': 0.30; 'compatible': 0.30; 'code': 0.31; 'point': 0.31; 'gets': 0.32; 'file': 0.32; 'could': 0.32; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'operations': 0.33; 'third': 0.34; 'ben': 0.35; 'open': 0.35; 'something': 0.35; 'add': 0.36; 'received:org': 0.36; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'rather': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'further': 0.61; 'improved': 0.62; 'close': 0.63; 'worth': 0.63; 'stuck': 0.65; 'business': 0.70; 'subject:The': 0.71; 'cut': 0.71; 'intelligent': 0.71; 'localized': 0.84; 'open,': 0.84; 'opener': 0.84; 'real- life': 0.84; "they'd": 0.84; 'dennis': 0.91; 'religion': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: The opener parameter of Python 3 open() built-in |
| Date | Tue, 04 Sep 2012 14:44:45 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <k2280c$nf1$1@speranza.aioe.org> <mailman.139.1346678967.27098.python-list@python.org> <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> <mailman.167.1346728806.27098.python-list@python.org> <87bohm8j73.fsf@benfinney.id.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | adsl-76-249-20-117.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 3.3/32.846 |
| X-No-Archive | YES |
| 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.189.1346784293.27098.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346784293 news.xs4all.nl 6861 [2001:888:2000:d::a6]:32887 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28420 |
Show key headers only | View raw
On Tue, 04 Sep 2012 15:12:48 +1000, Ben Finney
<ben+python@benfinney.id.au> declaimed the following in
gmane.comp.python.general:
>
> why not call that directly?
>
> f = opener(file, flags)
>
> It certainly is cleaner than either of the alternatives so far, and it
> doesn't add a parameter to the builtin.
>
But it returns an OS file descriptor... It doesn't return a Python
file object. From what I can tell, (I've just upgraded to Python 2.7
<G>) the opener is meant to replace the low-level function normally used
by Python's open(), and supplies an fd which gets wrapped by Python's
open().
>>> import os
>>> fd = os.open("somefile.txt", os.O_CREAT)
>>> type(fd)
<type 'int'>
>>> fo = open("somefile2.txt", "w")
>>> type (fo)
<type 'file'>
The two are not compatible except by using os.fdopen(fd) to get a
file object, or fo.fileno() to get the low-level file descriptor
>>> fo.fileno()
4
>>> fo1 = os.fdopen(fd, "w")
>>> type (fo1)
<type 'file'>
>>>
> > Furthermore, using "opener" could allow for a localized change to
> > affect all open statements in the module -- change file path, open for
> > string I/O rather than file I/O, etc.
>
> I don't know of any real-life code which would be significantly improved
> by that. Can you point us to some?
>
Not really -- but if they went one step further and supplied
"reader" and "writer" operations too, they'd get close to what I once
had to do in FORTRAN 77 under DEC VMS (by hooking in code to do double
buffering when reading data from magtape, while keeping the program
using regular F77 I/O statements; the open statement would do a pre-read
of one buffer and return; subsequent read statements would find a
pre-filled buffer, and issue an non-blocking read to fill the other
buffer -- cut the runtime for the program into a third or less as it was
no longer stuck waiting for slow mag-tape operations each time it did a
read). Implementing something like this in Python would likely require
"opener" to spawn a reader thread to do the I/O asynchronously, using a
limited Queue (1 buffer worth -- the reader thread would be the second
buffer, blocked on Q.put()), and a "reader" that would do Q.get() and
return the result to the Python read() logic for any parsing.
Okay, in Python, one could probably subclass "file", and override
the read methods -- but one would not be able to use the Python
open()... You'd have to do something like f = myFile(normal, open, args)
instead...
> --
> \ “I find the whole business of religion profoundly interesting. |
> `\ But it does mystify me that otherwise intelligent people take |
> _o__) it seriously.” —Douglas Adams |
> Ben Finney
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The opener parameter of Python 3 open() built-in Marco <marco_u@nsgmail.com> - 2012-09-03 14:32 +0200
Re: The opener parameter of Python 3 open() built-in Dave Angel <d@davea.name> - 2012-09-03 09:05 -0400
Re: The opener parameter of Python 3 open() built-in Marco <marco_u@nsgmail.com> - 2012-09-03 15:33 +0200
Re: The opener parameter of Python 3 open() built-in Marco <marco.buttu@gmail.com> - 2012-09-03 15:33 +0200
Re: The opener parameter of Python 3 open() built-in Christian Heimes <lists@cheimes.de> - 2012-09-03 15:29 +0200
Re: The opener parameter of Python 3 open() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-04 01:13 +0000
Re: The opener parameter of Python 3 open() built-in Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-03 23:19 -0400
Re: The opener parameter of Python 3 open() built-in Ben Finney <ben+python@benfinney.id.au> - 2012-09-04 15:12 +1000
Re: The opener parameter of Python 3 open() built-in Ben Finney <ben+python@benfinney.id.au> - 2012-09-04 15:20 +1000
Re: The opener parameter of Python 3 open() built-in Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-04 14:44 -0400
Re: The opener parameter of Python 3 open() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-04 05:25 +0000
Re: The opener parameter of Python 3 open() built-in Ben Finney <ben+python@benfinney.id.au> - 2012-09-04 15:45 +1000
Re: The opener parameter of Python 3 open() built-in Serhiy Storchaka <storchaka@gmail.com> - 2012-09-04 15:58 +0300
Re: The opener parameter of Python 3 open() built-in Terry Reedy <tjreedy@udel.edu> - 2012-09-04 15:16 -0400
Re: The opener parameter of Python 3 open() built-in Chris Angelico <rosuav@gmail.com> - 2012-09-05 08:18 +1000
Re: The opener parameter of Python 3 open() built-in Terry Reedy <tjreedy@udel.edu> - 2012-09-04 19:16 -0400
Re: The opener parameter of Python 3 open() built-in Antoine Pitrou <solipsis@pitrou.net> - 2012-09-06 00:34 +0000
Re: The opener parameter of Python 3 open() built-in Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-06 06:34 +0000
Re: The opener parameter of Python 3 open() built-in Serhiy Storchaka <storchaka@gmail.com> - 2012-09-03 19:06 +0300
Re: The opener parameter of Python 3 open() built-in Serhiy Storchaka <storchaka@gmail.com> - 2012-09-04 16:01 +0300
csiph-web