26th Jan 2020, 8:39 PM
PRO
PRO - avatar
16 odpowiedzi
+ 7
What's not working is the foul language in it! Fix that, and we'll talk about the rest.
26th Jan 2020, 8:50 PM
HonFu
HonFu - avatar
+ 4
Hey... I suddenly have an original and never in this thread already written idea: Let's store the return value!!! https://code.sololearn.com/cMBvMY2UD8MB/?ref=app
28th Jan 2020, 7:11 PM
HonFu
HonFu - avatar
+ 3
You can use function too, but then you have to return the file from the function. That would look like this: def open_file(): f = open("my_life.txt", "w+") return f my_file = open_file()
26th Jan 2020, 9:11 PM
HonFu
HonFu - avatar
+ 2
I don't think it would work. You open that file within a function, but after the function ends, it will be forgotten. Using my_file should lead to an error message. If you just open that file outside, without the function, it should work.
26th Jan 2020, 8:59 PM
HonFu
HonFu - avatar
+ 2
Can you copypaste the code again?
26th Jan 2020, 9:19 PM
HonFu
HonFu - avatar
+ 1
HonFu did that!!!plz explain the rest
26th Jan 2020, 8:50 PM
PRO
PRO - avatar
+ 1
ohh is it so
26th Jan 2020, 9:14 PM
PRO
PRO - avatar
+ 1
You didn't correctly copy what I wrote above. A function returns a value exactly to the point from where it was called. But if there's no pot to catch it, it all goes to waste. my_file = open_file() ^ pot!
26th Jan 2020, 9:27 PM
HonFu
HonFu - avatar
+ 1
When you return something from a function, you need to store it somewhere. my_file = ...
27th Jan 2020, 11:13 AM
HonFu
HonFu - avatar
+ 1
*sigh*
27th Jan 2020, 4:17 PM
HonFu
HonFu - avatar
+ 1
If a function is returning something it has to be stored too😐
28th Jan 2020, 7:09 PM
Huzaifa Khilawala
Huzaifa Khilawala - avatar
0
HonFu hmm yeah it does...but then do i ve to write the open function every time i write the close function...dont u think that's too much repetition of code
26th Jan 2020, 9:09 PM
PRO
PRO - avatar
0
nope bro HonFu i tried to return the file in function too.... but still i m getting the name error back
26th Jan 2020, 9:16 PM
PRO
PRO - avatar
0
HonFu def open_file(): my_file = open("my_life.txt", "w+") return my_file open_file() my_file.write("life doesnt work until u do\nso stop giving a worry bout ur conditions n start working ur butt off") my_file.close() open_file() print(my_file.read())
26th Jan 2020, 9:22 PM
PRO
PRO - avatar
0
HonFu i didnt get wt u said bro
27th Jan 2020, 11:01 AM
PRO
PRO - avatar
0
I think because you don't store in a variable when you return my_file. Like: file = open_file()
27th Jan 2020, 4:16 PM
Maxime Jacques