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: 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 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: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, 04 Sep 2012 15:12:48 +1000, Ben Finney 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 ) 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) >>> fo = open("somefile2.txt", "w") >>> type (fo) 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) >>> > > 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/