+ 1
In which mode does the 'with' function open a file?
can v use 'with' keyword to wright, read or append?
3 ответов
+ 1
if we don't mention anything what mode does it open in?
+ 1
'r' (read) is default mode. For other modes we may do something like this:
with open(filename, 'w') as wfile:
wfile.write(newline)
0
if you dont mention anything, it will be read mode. "r". if you want read, write, or append in binary, you add a letter b. "rb", "wb", "ab". it is very useful, when you want to write a structure(list, or dictionary) in a file, and later you want your program to use this data. in that case you can use json, and it works only if you open, read or write the file in binary. Excuse my poor english, i hope you understand.