datetime and from datetime import datetime on python
<p>how will i fix this problem on python. here's my code:</p>

<pre><code>    import time
    import datetime
    from time import mktime
    from datetime import datetime

    date = '20120814174530'
    date_to_strp = time.strptime(date, '%Y%m%d%H%M%S') #convert the value of date into strptime
    date_final = datetime.fromtimestamp(mktime(date_to_strp))
    #convert date_to_strp so so i can use it to subtract a value from a timedelta later

    date_substracted = date_final - datetime.timedelta(hours = 36)
</code></pre>

<p>this has an error:(type object 'datetime.datetime' has no attribute 'timedelta'),even though
i '<strong>import datetime</strong>',i think it was override by '<strong>from datetime import datetime</strong>',
and then when i interchange the position of '<strong>import datetime</strong>' and '<strong>from datetime import datetime</strong>',
the error would be ('module'object has no attribute 'fromtimestamp').</p>

<p>i can fix this both error with this code:</p>

<pre><code>    import time
    from time import mktime
    from datetime import datetime

    date = '20120814174530'
    date_to_strp = time.strptime(date, '%Y%m%d%H%M%S')
    date_final = datetime.fromtimestamp(mktime(date_to_strp))

    import datetime

    date_substracted = date_final - datetime.timedelta(hours = 36)
</code></pre>

<p>now,with this code,it is functioning properly. but what i want is that all import part
would be at the top as a good practice,any suggestion on how will i do that without any error with this situation or any suggestion on how will i code it in other way around.
thank you in advance.</p>
