FAQ

On Fri, Sep 11, 2015 at 3:54 AM, Steven D'Aprano wrote:
If the function is being called as if it were a procedure or command, that
is the return result is just ignored, I want to return one thing. But if it
is being called where the return result goes somewhere, I want to return
something else. Most importantly, I don't want to pass a flag to the
function myself, I want the function to know its own context.

The first thing that comes to mind is a repr hack. If you make your
function return an int-like object with a different repr, it could
look like it's returning "Awesome" interactively. The usefulness of
that depends on what the two forms are you're trying to return,
though.


Advantage: Doesn't get Ben's cabbage. I think.


Disadvantage: Looks weird if you try to debug stuff and get the repr
staring back at you.


ChrisA

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 19 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedSep 10, '15 at 5:54p
activeSep 11, '15 at 3:55p
posts19
users11
websitepython.org

People

Translate

site design / logo © 2017 Grokbase