how to create a file name with the current date & time in python?
<p>Here is a functional code (Create file with success)</p>

<pre><code>sys.stdout = open('filename1.xml', 'w')
</code></pre>

<p>Now I'm trying to name the file with the current Date Time (I'm not an expert in python)</p>

<pre><code>filename1 = datetime.now().strftime("%Y%m%d-%H%M%S")
sys.stdout = open(filename1 + '.xml', 'w')
</code></pre>

<p>I want to write out a file name with the exact date and time, it is a xml file, that the program has already create, I just need to name the file. The above code is not working.</p>

<p><strong>[EDITED]</strong> - The error returned</p>

<pre><code>  File "./fix.py", line 226, in &lt;module&gt;
    filenames = datetime.now().strftime("%Y%m%d-%H%M%S")
AttributeError: 'module' object has no attribute 'now'
</code></pre>

<p>Thanks!</p>
