Relative-importing *

Steve Holden steve at holdenweb.com
Tue Aug 7 08:35:59 CEST 2007


Marc 'BlackJack' Rintsch wrote:
> On Tue, 07 Aug 2007 02:45:23 +0000, rbygscrsepda wrote:
> 
>> Specifically, in Python 1.5, all of the following generate the error
>> below:
> 
> In Python *1.5*!?  I somehow doubt that.  ;-)
> 
>>     from . import *
>>     from .sibiling_package import *
>>     from .. import *
>>     from ..cousin_package import *
>>
>>     SyntaxError: 'import *' not allowed with 'from .'
>>
>> Importing * is a feature, but this seems like an artificial
>> inconsistency to me. It's as if the compiler raises an error when it
>> tries to import * as soon as it sees "from .", regardless of what
>> comes after it. So is this a bug in python? And if it happens to be a
>> bug, how can I alert the developers of the python compiler?
> 
> I'm just guessing here but as * imports are considered bad style the
> developers might took the opportunity to forbid them in relative imports
> because relative imports are new and this doesn't break old programs.
> 
Yup, I searched around to find a specific statement of the reason but 
couldn't find anything definite. Of course, if you are writing a set of 
plugins then wildcard imports would seem like a train wreck waiting to 
happen in terms of the discipline required to avoid name collisions.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list