file.write in Python

Python Methods and Functions

Writes the specified string to the file.

file.write (str)

-> None | int

str - The string to be written to the file. 


+ py3.0 Returns the number of bytes written (previously returned None ). 

  with open (`my_file.txt`,` w`) as f: 
f.write (`some`) # 4
< / code>

Note

Output to a file is buffered, so data may not get to the file system immediately, to force writing use file.flush () , or file.close () .





Get Solution for free from DataCamp guru