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

Chris Angelico rosuav at gmail.com
Tue Oct 13 06:04:52 EDT 2020


On Tue, Oct 13, 2020 at 9:03 PM D'Arcy Cain <darcy at vybenetworks.com> wrote:
>
> On 10/12/20 7:20 AM, Chris Angelico wrote:
> > This is yet another reason that "from MODULE import *" is a bad idea.
> > Instead, just import the module itself, and take whatever you need.
>
> Or just import the objects that you need;
>
> from datetime import datetime, SYMBOL, etc...
>
> I use Decimal a lot.  I would hate to have to write "decimal.Decimal(str)"
> for example.
>
> Whichever method you use the most important thing is to be consistent as
> much as possible.

Yep - either "import module" or "from module import name", but not
"import *". Be precise. Be efficient. Have a plan to import every
module you meet.

ChrisA


More information about the Python-list mailing list