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 258 views
258 views asked Jun 22, 2020 by avibootz
1 answer 195 views
2 answers 362 views
2 answers 209 views
1 answer 156 views
...