0
About this below Code
Language:Python msg = "Hello world!" file = open("newfile.txt", "w") amount_written = file.write(msg) print(amount_written) file.close() Output: 12 I have a doubt here 1)Why does it print length of the string rather than printing "Hello World! "? 2)Why do we have to use another varaible "amount_written" here if we run the code like this msg = "Hello world!" file = open("newfile.txt", "w+") file.write(msg) print(file.read()) file.close() Output: No output Can anyone please Explain this ? Thank you
7 Answers
+ 1
You must Close the File and Open it again
0
Even that will print the length
0
But its "W+" it means write and read why do i need to close it again
0
I don't think it was saved until it was closed
0
But without using len how does the program show "12" as output
- 1
Try Print(len(file.read()))