+ 5
How get RETURN... from func, without other str? And dont delete something to func
17 Respuestas
+ 3
a bit gaga, but it does rhe job
https://code.sololearn.com/cuo8pLpq1Naw/?ref=app
+ 10
Conditional printing function
https://code.sololearn.com/c533oiE5YGpS/#py
+ 4
this is better:
https://code.sololearn.com/cja32mtbJ7ne/?ref=app
+ 3
I'm assuming that what you're trying to achieve is to redirect `sys.stdout` (where the `print` built-in write to by default if no `file` argument is given) on third-party code that you can't modify.
Oma already showed you one solution, however, there's a much simpler and better way to approach this. Starting with Python 3.4, the `contextlib` standard module provides the `redirect_stdout` context-manager, which, under the hood, does something similar to Oma's decorator approach, as well as restoring `stdout` when exiting the context, along with the clear and straightforward syntax of the `with` statement.
Here's a rather minimal example,
https://code.sololearn.com/c9ikm1diAcbe/?ref=app
I suggest you read the relevant documentation for more detailed info about this function, https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout .
+ 2
So you want the string to not be printed? Then you need to remove it from the function.
In your code, when you call func() you will execute the code in that block. If you call func you actually get a 'reference' to that function - on the last line of your second code try removing the comparison and see what prints. This is what is allows you to assign functions to other variables. This is why nothing prints when you write func. But also nothing returns, because you aren't calling the function
+ 2
Explain WHY you want to do this code, perhaps there is an alternate solution if we know the bigger problem.
Dan Walker commented a good understanding of your code
here is an example and possible solution
https://code.sololearn.com/c8YhD2T2t1Eq
+ 2
Yan I made a challenge from that since it is tricky
https://www.sololearn.com/discuss/1369216/?ref=app
+ 2
pls am asking of what is aurdio program
+ 2
Edgar Garrido very interesting! thanks for example!
+ 1
def func():
return True
+ 1
Oma Falk, Thank you!
+ 1
Thanks for my mention!
0
delete it from the function. then it won't print when you call it.
0
without delete anything from func.
(only get return)
0
then you have to add something, like an argument, that controls for what gets printed.
0
i need get result only from RETURN, without delete anything from func