+ 1

After

When I run the following, I get "NONE" instead of the amount of bytes in the file that was written. msg = "Hello everyone!" file = open("//Users/michaelking/Downloads/helloworld3.html","w") amount_written = file.write(msg) print(amount_written) file.close() WHY do I get NONE? It should Be 15

6th Sep 2020, 6:24 PM
Michael King
Michael King - avatar
6 odpowiedzi
+ 4
When i remove the path you are using and only keep the file name, the code works ok for me as expected. Have you done this try already? 'None' means, that the system can not write to the file. Do you have the permission to write to that location?
6th Sep 2020, 6:35 PM
Lothar
Lothar - avatar
+ 3
Oma Falk , file.write() returns the number of bytes written to a file. If nothing is written it returns 'None'. this is a part of the python docs: f.write(string) writes the contents of string to the file, returning the number of characters written.
6th Sep 2020, 7:33 PM
Lothar
Lothar - avatar
+ 3
Lothar ahhh thanks😀😀
6th Sep 2020, 7:38 PM
Oma Falk
Oma Falk - avatar
+ 3
I did a try with iOS on Apple and on Windows 10. On both systems the code writes the string to the file and returns the number of bytes written.
6th Sep 2020, 7:40 PM
Lothar
Lothar - avatar
+ 2
I have successfully written "Hello everyone" to the specified file. But in the exercise on SoloLearn, they print the number of bytes that was written.
6th Sep 2020, 6:58 PM
Michael King
Michael King - avatar
+ 1
15?????
6th Sep 2020, 6:30 PM
Oma Falk
Oma Falk - avatar