Context-aware return

Laura Creighton lac at openend.se
Thu Sep 10 14:40:49 EDT 2015


In a message of Fri, 11 Sep 2015 03:54:14 +1000, "Steven D'Aprano" writes:

>def func():
>    do_stuff()
>    if procedure:  # FIXME what goes here???
>        return "Awesome"
>    else:
>        return 999
>
>Now I can do this:
>
>
>x = func()
>assert x == 999
>
>L = [1, 2, func(), 4]
>assert L[2] == 999
>
>func()
># interactive interpreter prints "Awesome"
>
>Is such a thing possible, and if so, how would I do it?

Why, why, why do you want such a horrid thing?
I have an function that isn't always doing what I want.
I make a reference to it, so I can print it from time to time,
and do some other things to try to see why sometimes I am getting
an unwanted result.

I can no longer debug my problem.
You are seriously proposing this?

>If I did this thing, would people follow me down the street booing and
>jeering and throwing things at me?

I might start ahead of time, just for thinking of it ...

There has got to be a better way to get what you want -- or perhaps
for you to want something saner.

Laura



More information about the Python-list mailing list