Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28387
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail |
|---|---|
| From | Ben Finney <ben+python@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: The opener parameter of Python 3 open() built-in |
| 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> |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| Date | Tue, 04 Sep 2012 15:12:48 +1000 |
| Message-ID | <87bohm8j73.fsf@benfinney.id.au> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
| Cancel-Lock | sha1:MqYGjSWd1livzLNQfV3Cw9LMoIs= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Lines | 46 |
| Organization | Unlimited download news at news.astraweb.com |
| NNTP-Posting-Host | 46f60f4b.news.astraweb.com |
| X-Trace | DXC=Yhncg=efm=?hn]AcMfkkb9L?0kYOcDh@:^gYlR9D^Ya6E3=kG9hhb72<Ah6b28J?E4bEW9A[5UK?5NZ[SL`C\Kg31hP0?=e2U92 |
| Xref | csiph.com comp.lang.python:28387 |
Show key headers only | View raw
Dennis Lee Bieber <wlfraed@ix.netcom.com> writes:
> On 04 Sep 2012 01:13:09 GMT, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> declaimed the following in
> gmane.comp.python.general:
> > What is the rationale for complicating [the builtin] open instead of
> > telling people to just call their opener directly?
>
> To avoid the new syntax would mean coding the example as
>
> f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w")
>
> which does NOT look any cleaner to me... Especially not if "opener" is
> to be used in more than one location.
Exactly. That's not what was asked, though. Steven asked why not call
the opener.
So, having written the opener:
> On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote:
> > import os
> >
> > def opener(file, flags):
> > return os.open(file, flags | os.O_EXCL)
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.
> 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?
--
\ “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
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