PyWart: Import resolution order

88888 Dihedral dihedral88888 at googlemail.com
Sun Jan 13 04:56:22 CET 2013


Ian於 2013年1月12日星期六UTC+8下午3時36分43秒寫道:
> On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson
> 
> <rantingrickjohnson at gmail.com> wrote:
> 
> > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote:
> 
> >> Why is it better to import from the current directory first?
> 
> >
> 
> > Opps. I was not explicit enough with my explanation :). I meant, "look in the current directory FIRST when in a package". Since many times (most all times) packages will contain many sub-modules that need to be imported into the package's main.py module, and sometimes these modules will have the same name as a stdlib module, then looking in the package FIRST makes sense.
> 
> 
> 
> And again, in Python 2.x this is already the case.  When importing in
> 
> a package, it tries to do a relative import before it even looks at
> 
> sys.path.
> 
> 
> 
> > I think if python where *strict* about full paths for non-builtins, then we would be in a better place.
> 
> 
> 
> And again, in Python 3, where implicit relative imports have been
> 
> removed from the language, it already is strict about using full
> 
> paths.  You can still do relative imports, but you have to be explicit
> 
> about them.
> 
> 
> 
> > For instance you could create a package named "chris" and then have a module named math exist inside. Alternatively if you choose to be a non-professional and create a math module without a containing package, python would throw the module into the default "lib" package. The only way you could access your math module now would be by using the path "lib.math".
> 
> 
> 
> What if I create a package named "math"?  Does that also automatically
> 
> get renamed to "lib.math"?  How is it decided what package names are
> 
> proper; is it just because it happens to clash with a stdlib name that
> 
> the package gets magically renamed?
> 
> 
> 
> What if I create a package, and then later a module with the same name
> 
> happens to be added to the stdlib?  My program that uses the package
> 
> just breaks because it no longer imports the correct thing?
> 
> 
> 
> > Damn i am full of good ideas!
> 
> 
> 
> Your ideas might be better if you first spent some time gaining a
> 
> better understanding of how the language works as is.

OK, I think to develop a GUI with auto-code 
translations in an IDE  with python as the CAD/CAM scripting  language can be helpful.

But usually this kind of sotware projects is in the 
commercial part. 




More information about the Python-list mailing list