What might cause my sample program to forget that already imported datetime?

Richard Damon Richard at Damon-Family.org
Mon Oct 12 09:11:24 EDT 2020


On 10/12/20 7:20 AM, Chris Angelico wrote:
> On Mon, Oct 12, 2020 at 9:58 PM Abdur-Rahmaan Janhangeer
> <arj.python at gmail.com> wrote:
>> Btw why a datetime in datetime?
>>
>> It causes much confusion. I dont know
>> the design decision behind, if someone knows, it might be good to explain
>>
> There are quite a few modules that have one "most obvious" entrypoint,
> and there's really no better name for either that thing or the module
> it lives in. The pprint module has a pprint function, giving the same
> phenomenon.
>
> This is yet another reason that "from MODULE import *" is a bad idea.
> Instead, just import the module itself, and take whatever you need.
>
> ChrisA

And if you don't like doing datetime.datatime all the time, you can also do

from MODULE import SYMBOL

and do

from MODULE import SYMBOL as ALIAS

when you get conflicts.

The big issue is that you lose control with * as it pulls 'arbitrary'
things into your name space.

I do sometimes do things like the combination

import MODULE

from MODULE import SYMBOL

if there is some name in the module I want to use a lot.

I don't see much need for:

import MODULE

from MODULE import *

as if you are bringing in ALL the names into the current module name
space, when will you need to use the module.symbol notation?

-- 
Richard Damon



More information about the Python-list mailing list