why import * only allowed at module level?

Peter Hansen peter at engcorp.com
Mon Jan 14 01:05:08 EST 2002


Simo Salminen wrote:
> 
> How come python 2.2 does not allow code like this:
> 
> >>> def a():
> ...     from os import *
> <interactive input>:1: SyntaxWarning: import * only allowed at module level
> 
> Why this was changed? I like to do import * at function level because
> it is handy but doesn't pollute namespace.

It actually does work (try it!) but you're getting a *warning*
now where before you got none.  I can't say why you're getting
a warning though, but you can change that (see the standard
module 'warnings').



More information about the Python-list mailing list