How to write string (text) to a text file in Python

2 Answers

0 votes
fh = open("d:\data.txt", "w")
fh.write("python\njava\nc#\n")
fh.close()


'''
run:

data.txt
--------
python
java
c#

'''

 



answered Dec 20, 2017 by avibootz
0 votes
with open("d:\data.txt", "w") as fh:
    fh.write("python\njava\nc#\nphp\n")


'''
run:

data.txt
--------
python
java
c#
php

'''

 



answered Dec 20, 2017 by avibootz

Related questions

2 answers 267 views
267 views asked Jun 22, 2020 by avibootz
1 answer 198 views
2 answers 367 views
2 answers 213 views
1 answer 162 views
...