# 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"
filepath = 'Iliad.txt'
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
print("Line {}: {}".format(cnt, line.strip()))
line = fp.readline()
cnt += 1
file = open("sample.txt", "w")
file.write("Hello
")
file.write("World
")
file.close()