Argparse Reopening file.
<p>I'm using the argparse module and I have a log file which is continuously appended to. I want to open args.file, do something with the content, then close it and opening it again after some time. </p>

<p>An example piece of code:</p>

<pre><code>import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument('file',type=file)
args = parser.parse_args()

for _ in range(3):
    data = args.file.read()
    print data
    time.sleep(3)
</code></pre>

<p>Note that args.file.seek(0) is no solution here. I can close the file with args.file.close() but how to open it again? </p>

<p>I can make the filename-argument just a normal string of the filename but i would like to know a solution keeping the argumenttype as a filename. </p>

<p>you can open it again using</p>

<pre><code>args.file = open(args.file.name)
</code></pre>

python io argparse