+ 5

How get RETURN... from func, without other str? And dont delete something to func

https://code.sololearn.com/cZb79kaBosJ1/?ref=app

25th Jun 2018, 7:21 PM
Yan
Yan - avatar
17 RĂ©ponses
+ 3
a bit gaga, but it does rhe job https://code.sololearn.com/cuo8pLpq1Naw/?ref=app
25th Jun 2018, 10:03 PM
Oma Falk
Oma Falk - avatar
+ 10
Conditional printing function https://code.sololearn.com/c533oiE5YGpS/#py
2nd Jul 2018, 8:52 AM
CĂ©pagrave
CĂ©pagrave - avatar
27th Jun 2018, 8:55 PM
Oma Falk
Oma Falk - avatar
+ 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 .
28th Jun 2018, 2:25 AM
Edgar Garrido
Edgar Garrido - avatar
+ 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
25th Jun 2018, 9:55 PM
Dan Walker
Dan Walker - avatar
+ 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
26th Jun 2018, 6:05 AM
sharpProgrammer
sharpProgrammer - avatar
+ 2
Yan I made a challenge from that since it is tricky https://www.sololearn.com/discuss/1369216/?ref=app
26th Jun 2018, 10:06 AM
Oma Falk
Oma Falk - avatar
+ 2
pls am asking of what is aurdio program
26th Jun 2018, 8:49 PM
Itz ABUBAKAR HÃBÙKHÃÑ
+ 2
Edgar Garrido very interesting! thanks for example!
28th Jun 2018, 3:31 AM
Oma Falk
Oma Falk - avatar
+ 1
def func(): return True
25th Jun 2018, 7:48 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 1
Oma Falk, Thank you!
26th Jun 2018, 9:02 AM
Yan
Yan - avatar
+ 1
Thanks for my mention!
26th Jun 2018, 10:09 AM
Yan
Yan - avatar
0
delete it from the function. then it won't print when you call it.
25th Jun 2018, 7:39 PM
deep_unlearning
deep_unlearning - avatar
0
without delete anything from func. (only get return)
25th Jun 2018, 7:48 PM
Yan
Yan - avatar
0
then you have to add something, like an argument, that controls for what gets printed.
25th Jun 2018, 7:50 PM
deep_unlearning
deep_unlearning - avatar
0
i need get result only from RETURN, without delete anything from func
25th Jun 2018, 8:47 PM
Yan
Yan - avatar
27th Jun 2018, 3:03 AM
Majd Zaitun
Majd Zaitun - avatar