You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The interpreter session creates a scope which makes newly declared functions, import and variables unable to be used in lambda functions and pandas dataframe indexing.
With [the suggested fix], the following code should work while not working using the default embedded shell:
a=3
(lambda :a)() # default behavior: name 'a' is not defined
import time
(lambda: time.time())() # default behavior: name 'time' is not defined
(default behavior is due to a and time are not added to globals() and ipython does not make closures for local functions (the lambdas defined above) and insists to look up the variables in global scope. search closure in this page)
A permanent solution is necessary, but a temporary fix to the problem is to run globals().update(locals()) after defining any new variables before trying to use them in a lambda-function-type situation.
The text was updated successfully, but these errors were encountered:
The interpreter session creates a scope which makes newly declared functions, import and variables unable to be used in lambda functions and pandas dataframe indexing.
https://stackoverflow.com/questions/35161324/how-to-make-imports-closures-work-from-ipythons-embed
A permanent solution is necessary, but a temporary fix to the problem is to run
globals().update(locals())
after defining any new variables before trying to use them in a lambda-function-type situation.The text was updated successfully, but these errors were encountered: