This works as expected
def outer_func():
from time import *
print time()
outer_func()
I can define nested functions in the context fine and call them from other nested functions:
def outer_func():
def time():
return '123456'
def inner_func():
print time()
inner_func()
outer_func()
I can even import individual functions:
def outer_func():
from time import time
def inner_func():
print time()
inner_func()
outer_func()
This, however, throws SyntaxError: import * is not allowed in function 'outer_func' because it contains a nested function with free variables
:
def outer_func():
from time import *
def inner_func():
print time()
inner_func()
outer_func()
I'm aware this isn't best practice, but why doesn't it work?