Write string to a file : Text File Write « File « Python






Write string to a file


f = open('somefile.txt', 'w')
f.write('Hello, ')
f.write('World!')
f.close()


           
       








Related examples in the same category

1.Demonstrates writing to a text fileDemonstrates writing to a text file
2.Reading the newly created file.Reading the newly created file.
3.Creating a text file with the writelines() method.Creating a text file with the writelines() method.