0

Why I can't read the file

m = open('hi',"w") m.write('hello') m.close g = open('hi', "r") a = g.read() print(a)

11th Jul 2022, 12:55 AM
Bean Hong
4 Answers
+ 4
You're not closing file <m>, remember to call a method, we need to (at least) put empty parentheses after method name - when the method has no parameter. m.close() # you forgot the () - parentheses. Don't forget to close file <g> correctly.
11th Jul 2022, 1:27 AM
Ipang
+ 1
Thanks you it work . But one thing I don't understand in file mode "w+" I can write on it but I can't read on that mode
11th Jul 2022, 6:06 AM
Bean Hong
+ 1
Try to read this page, hopefully it helps clarify your doubt https://realpython.com/read-write-files-JUMP_LINK__&&__python__&&__JUMP_LINK/
11th Jul 2022, 6:25 AM
Ipang
0
import logging logging.basicConfig(level=logging.debug,filename ='hi.txt', filemode= 'w',format= '%(asctime)s') logging.debug('from debug' )
25th Jul 2022, 6:10 PM
Bean Hong