I am trying to learn python and wanted to write some text to a file. I came across two kind of file objects.
fout=open("abc.txt",a)
with open("abc.txt",a) as fout:
The following code:
f= open("abc.txt", 'a')
f.write("Step 1\n")
print "Step 1"
with open("abc.txt", 'a') as fout:
fout.write("Step 2\n")
Gave the output:
Step 2
Step 1
And the following code:
f= open("abc1.txt", 'a')
f.write("Step 1\n")
f= open("abc1.txt", 'a')
f.write("Step 2\n")
Gave the output:
Step 1
Step 2
Why is there difference in the outputs?