On Wed, 2007-01-10 at 11:55 -0600, John Hunter wrote:
> >>>>> "Steve" == Steve Chaplin <[EMAIL PROTECTED]> writes:
> 
>     Steve> Matplotlib does use a lot of relative imports which I think
>     Steve> is bad style.
> 
>     Steve> See PEP 8 "Style Guide for Python Code"
>     Steve> http://www.python.org/dev/peps/pep-0008/
> 
>     Steve>     - Relative imports for intra-package imports are highly
>     Steve> discouraged.  Always use the absolute package path for all
>     Steve> imports.  Even now that PEP 328 [7] is fully implemented in
>     Steve> Python 2.5, its style of explicit relative imports is
>     Steve> actively discouraged; absolute imports are more portable
>     Steve> and usually more readable.
> 
> I have never run into a problem with relative imports, though I don't
> object to removing them.  Why are they bad style and what is the danger?

Its because you can unwittingly end up with module name clashes. There
can be two different modules in two different directories with the same
name and you import the wrong module by mistake. It happened to me once
when I created a 'calendar.py' module and didn't realize that Python
already has a calendar module. Its hard to debug because you get a
traceback which makes no sense.

>From PEP328
http://www.python.org/dev/peps/pep-0328/

Rationale for Absolute Imports
In Python 2.4 and earlier, if you're reading a module located inside a
package, it is not clear whether

import foo

refers to a top-level module or to another module inside the package. As
Python's library expands, more and more existing package internal
modules suddenly shadow standard library modules by accident. It's a
particularly difficult problem inside packages because there's no way to
specify which module is meant. To resolve the ambiguity, it is proposed
that foo will always be a module or package reachable from sys.path.
This is called an absolute import.

Steve

Send instant messages to your online friends http://au.messenger.yahoo.com 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to