This program (written in Python) is supposed to display only the first two lines of text written to a particular file. However when I run it, though it has no errors it doesn't display any output, in the IDE nor on the file itself.
def file_read_from_head(fname, nlines):
from itertools import islice
with open(fname) as f:
for line in islice(f, nlines):
print(line)
f = open('test.txt', 'w')
f.write = ("Hello welcome to Python \n"
"THis is the second line \n"
"This is the third line \n")
print(file_read_from_head('test.txt', 2))