Does anyone know why this writing to .txt file doesn't work?
<p>When I run this code and input values for <code>crop</code> and <code>quantity</code> it doesn't write them to <code>crop database.txt</code> like it should, but just creates <code>crop database.txt</code> as a new blank text file. Does anyone know why this is? Is it because of the way I am closing the file?</p>

<pre><code>crop = input("Which crop? ")
quantity = input("How many? ")

with open ('cropdatabase.txt', 'a+') as file:

 lines = file.readlines()

file.close ()

with open ('cropdatabase.txt', 'a+') as file:

 for row in lines:

    if crop in row:

       row = str(a)
       split_2 = a.split (',')
       split_2.append (quantity)

    else:

       file.write ('\n')
       file.write (crop + ' ')
       file.write (quantity + ' ')

file.close ()
</code></pre>