Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python write to text file with new line

# This will open a new file called myFile.txt and 
# write 0 - 4 using a loop, each on a new line.
# Note the "
" part!

with open("myFile.txt", "w") as file:
  for i in range(0,5):
    file.write(str(i) + "
")

# We do not need to use "file.close()" because 
# we used "with open(...)" which is considered 
# to be more "pythonic"
 
PREVIOUS NEXT
Tagged: #python #write #text #file #line
ADD COMMENT
Topic
Name
4+3 =