[Python-ideas] Allow imports to a global name

Steven D'Aprano steve at pearwood.info
Wed Apr 11 12:42:02 CEST 2012


Raymond Hettinger wrote:
> On Apr 10, 2012, at 8:59 PM, Nick Coghlan wrote:
> 
>> . FWIW, I'm actually in favour of dropping everything after the
>> "or" in that paragraph from the language spec, since we don't enforce
>> *any* of it. 
> 
> +1  The restriction seems unnecessary to me.
> 
> That being said, we should check to make sure that the other
> implementations don't need the restrictions for some reason or other.



Seems to work with Jython:

steve at runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
 >>> def test():
...     global math
...     import math
...
 >>>
 >>> test()
 >>> math
<type 'org.python.modules.math'>



-- 
Steven



More information about the Python-ideas mailing list