+ 2
what if we add "b" to a mode for text files?
Opening Files, Python I know that adding "b" to a mode opens it in binary mode, which is used for non-text files (such as image and sound files). But what what for text files?
5 Respostas
+ 1
Suraj Das nice if you tried it on your own. I told that because many users ask questions here without trying it on their own.
Sorry for the above answer caused by the misunderstandment.
Well here is the answer, binary mode is used to load a buffer of bites into the stream. Most of the time the data read from the non-text files cannot be encoded properly. But there is no difference between the chunk returned by the normal files when reading using normal and binary mode (as the stored bytes are encodable)
You can try the following code
file = open("file.txt", "rb").read() --the byte stream
print(file.decode()) --prints the file in a proper encoding (not much difference in text files)
+ 2
thank you Seniru
- 1
Try it yourself!
https://www.sololearn.com/discuss/1316935/?ref=app