Created
September 30, 2015 00:03
-
-
Save ssanderson/1067c7ac267aedfa7865 to your computer and use it in GitHub Desktop.
Import * inside an inner function fails only if that function references variables defined outside the function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def outer(): | |
... def inner(): | |
"Fails with SyntaxError" | |
... from numpy import * | |
... return array | |
... return inner() | |
... | |
<stdin>:2: SyntaxWarning: import * only allowed at module level | |
File "<stdin>", line 3 | |
SyntaxError: import * is not allowed in function 'inner' because it is a nested function | |
>>> def outer(): | |
... def inner(): | |
"Warns, but doesn't fail!" | |
... array = 3 | |
... from numpy import * | |
... return array | |
... return inner() | |
... | |
<stdin>:2: SyntaxWarning: import * only allowed at module level | |
>>> outer() | |
<built-in function array> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment