On 2014-11-22 23:25, Steven D'Aprano wrote:
> Having said that, it's not fair to blame the user for shadowing
> standard library modules:
> 
> - All users start off as beginners, who may not be aware that this
> is even a possibility;

While it's one thing to explicitly shadow a module (creating your own
module named "calendar"; if you need the stdlib module, you know it
and have to rename your local one), the implicit shadowing has stung
me a number of times.  I'll unthinkingly create an "email.py" and
then need to send email so I'll import smtplib (which internally
imports stdlib's email.py but it finds my local email.py) and
everything falls over. The error messages don't make it obvious what
happened.

I've been burned enough times that I now know not to do this. But it
was certainly burned into my mind after the 3rd time it happened.

> > And after all that, it would still fail if you happened to want to
> > import both "calendar" modules into the same module.
> 
> __path__ = []
> import calendar
> __path__ = ['my/python/modules']
> import calendar as mycalendar

Hrm.  Never knew this.  Could you point me at some docs on that?
(searching for "__path__" on python.org isn't turning up much that
jumps out at me as being correlated)

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to