Is there a conflict of libraries here?

Frank Millman frank at chagford.com
Fri Nov 6 02:36:02 EST 2020


On 2020-11-06 9:25 AM, Steve wrote:
> In my program, I have the following lines of code:
> 
>      import random
> 
>      import re
> 
>      import time
> 
>      import datetime
> 
>      from datetime import timedelta
> 
>      from time import gmtime, strftime ##define strftime as time/date right
> now
> 
>      import winsound as ws
> 
>      import sys
> 
> These may or may not affect my new program code but here is the issue:
> 
>   
> 
> If I add the code:
> 
>        from datetime import datetime
> 
> these new lines work:
> 
>             dt = datetime.fromisoformat(ItemDateTime)
> 
>             dt_string = dt.strftime(' at %H:%M on %A %d %B %Y')
> 
> and will fail without that "datetime import datetime" line
> 
>   
> 
> however;
> 
>   
> 
> With that "datetime import datetime" line included,
> 
> all of the lines of code throughout the program that contain
> "datetime.datetime" fail.
> These have been in use for over three years and there are at least a dozen
> of them.
> 
> The error produced is:
> 
> 
>      time1  = datetime.datetime.strptime(T1, date_format)
> 
>      AttributeError: type object 'datetime.datetime' has no attribute
> 'datetime'
> 

I think all you have to do is -

1. Remove the line 'from datetime import datetime'.

2. Change dt = datetime.fromisoformat(ItemDateTime) to
           dt = datetime.datetime.fromisoformat(ItemDateTime)

Unless I have missed something, that should work.

Frank Millman



More information about the Python-list mailing list