Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96301

Re: Context-aware return

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail
From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: Context-aware return
Date Thu, 10 Sep 2015 20:27:10 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 52
Message-ID <mssp2u$7m7$1@reader1.panix.com> (permalink)
References <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <msslas$pf8$1@reader1.panix.com> <mailman.339.1441916238.8327.python-list@python.org>
NNTP-Posting-Host 67-130-15-94.dia.static.qwest.net
X-Trace reader1.panix.com 1441916830 7879 67.130.15.94 (10 Sep 2015 20:27:10 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Thu, 10 Sep 2015 20:27:10 +0000 (UTC)
User-Agent slrn/1.0.2 (Linux)
Xref csiph.com comp.lang.python:96301

Show key headers only | View raw


On 2015-09-10, Akira Li <4kir4.1i@gmail.com> wrote:
> Grant Edwards <invalid@invalid.invalid> writes:
>
>> On 2015-09-10, Steven D'Aprano <steve@pearwood.info> wrote:
>>
>>> I have a function which is intended for use at the interactive interpreter,
>>> but may sometimes be used non-interactively. I wish to change it's output
>>> depending on the context of how it is being called.
>>
>> [...]
>>
>> Sounds like an excellent way to waste somebody's afternoon when they
>> start to troubleshoot code that's using your function.  Over and over
>> and over we tell newbies who have questions about what something
>> returns or how it works
>>
>>     "Start up an interactive session, and try it!".
>>
>> If word gets out about functions like yours, we sort of end up looking
>> like twits.  
>>
>>> If I did this thing, would people follow me down the street booing
>>> and jeering and throwing things at me?
>>
>> Only the people who use your function. :)
>
> There are cases when it might be justified to alter the behavior e.g.,
> *colorama* allows to strip ANSI codes (e.g., disable colored output) if
> stdout is not a tty or *win-unicode-console* make sys.stdout to use
> WriteConsoleW() to write Unicode to Windows console (interactive case).

I hate that sort of behavior also, but there's a long historical
precident on Unix of command line utilities changing output format
based on the results of isatty(STDIN_FILENO).  IMO, that was
definitely a mistake, and to this day regularly wastes my time when
troubleshooting bash programs. But, it's been that way for 45 years,
and it's not going to get fixed now.  That sort of auto-magical
"trying to guess what the user wants" instead of doing what the user
says is what makes PHP smell so bad.  

A bad idea copied by thousand of people over several decades is still
a bad idea.

Let's not duplicate that mistake in Python.
   
But, just to clarify, we're talking about the function's return value,
not what it writes to stdout, right?

-- 
Grant Edwards               grant.b.edwards        Yow! I would like to
                                  at               urinate in an OVULAR,
                              gmail.com            porcelain pool --

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Context-aware return Steven D'Aprano <steve@pearwood.info> - 2015-09-11 03:54 +1000
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:03 +0200
  Re: Context-aware return Ben Finney <ben+python@benfinney.id.au> - 2015-09-11 04:12 +1000
  Re: Context-aware return Ben Finney <ben+python@benfinney.id.au> - 2015-09-11 04:14 +1000
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:21 +0200
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:24 +0200
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:34 +0200
  Re: Context-aware return Chris Angelico <rosuav@gmail.com> - 2015-09-11 04:39 +1000
  Re: Context-aware return Laura Creighton <lac@openend.se> - 2015-09-10 20:40 +0200
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:45 +0200
  Re: Context-aware return "Sven R. Kunze" <srkunze@mail.de> - 2015-09-10 20:56 +0200
  Re: Context-aware return Paul Rubin <no.email@nospam.invalid> - 2015-09-10 12:19 -0700
  Re: Context-aware return Grant Edwards <invalid@invalid.invalid> - 2015-09-10 19:23 +0000
    Re: Context-aware return Akira Li <4kir4.1i@gmail.com> - 2015-09-10 23:15 +0300
      Re: Context-aware return Grant Edwards <invalid@invalid.invalid> - 2015-09-10 20:27 +0000
    Re: Context-aware return random832@fastmail.us - 2015-09-10 16:42 -0400
    Re: Context-aware return Rustom Mody <rustompmody@gmail.com> - 2015-09-11 08:55 -0700
    Re: Context-aware return Rustom Mody <rustompmody@gmail.com> - 2015-09-11 08:55 -0700
  Re: Context-aware return Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-11 00:41 +0000
    Re: Context-aware return Ned Batchelder <ned@nedbatchelder.com> - 2015-09-12 16:27 -0700
      Re: Context-aware return Steven D'Aprano <steve@pearwood.info> - 2015-09-17 12:31 +1000
  Re: Context-aware return Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-12 03:11 +0100

csiph-web