Is there a conflict of libraries here?

Mats Wichmann mats at wichmann.us
Sat Nov 7 17:16:27 EST 2020


On 11/7/20 11:26 AM, Steve wrote:
> Ok, I think I see a light in the fog.
> 
>   
> 
> It looks as if I can identify a variable to contain a library.
> 
> Import datetime as dt1
> 
>   
> 
> I guess that I can have a second variable containing that same library:
> 
> Import datetime as dt2
> 
>   
> 
> Should I presume that not doing this is what caused the interference in my
> code?
> 
>   
> 
> In your example:
> 
>>>> import datetime as dt
> 
>>>> from datetime import datetime
> 
>>>> globals()
> 
> {'__name__': '__main__', '__doc__': None, '__package__': None,
> 
> '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__':
> 
> None, '__annotations__': {}, '__builtins__': <module 'builtins'
> 
> (built-in)>, 'dt': <module 'datetime' from
> '/usr/lib64/python3.8/datetime.py'>,
> 'datetime': <class 'datetime.datetime'>}
> 
>   
> 
> How does your line3 and line2 relate to line1?
> It looks as if they relate to dt but it is not specifically stated.  Is it
> because they are consecutive lines?
> 
> In the list of globals, I see :{}, seems bizarre..

it was just to show that the symbol 'dt' refers to the module object for 
datetime, and the symbol 'datetime' refers to the datetime class from 
the datetime module - since they're different names they can coexist; 
earlier when you imported both as datetime, the second one overwrote the 
first one.  Sorry, I'm probably confusing you more.




More information about the Python-list mailing list