Action after writing to txt
<p>Is there anyway I can check, once that the .txt file has been written? Is this able to be done with a while condition?</p>

<p>For example:</p>

<pre><code>writetotxt = open(mytxt, 'w')
writetotxt.write('Line 1' + '\n')
writetotxt.write('Line 2')
writetotxt.close()

def txtwritten():
    firstline = linecache.getline(mytxt, 1)
    secline = linecache.getline(mytxt, 2)
    check = firstline + secline
</code></pre>

<p>But, while the process, it returns a blank result. When it is finished writing to text file, then it displays line 1 and 2.</p>

<p>Can a for condition be set to determine whether it is finished writing to the txt?</p>

<p>Also look at the <code>flush()</code> file method call and the <code>buffering</code> argument to <code>open</code>.</p>

<p>Two reasons that trying to read immediately after writing:</p>

<ol>
<li>you're not opening the file to allow reading (need to open with mode <code>w+</code> to allow reading)</li>
<li>files are buffered by default: calls to <code>write()</code> add to the buffer; until the buffer fills up, a <code>flush()</code> call is made, or the file is closed, the contents of the buffer will not actually be written to disk.</li>
</ol>

python variables