PYCHARM VS JUPYTER HOW TO
PYCHARM VS JUPYTER CODE
So if you were to run the code in your example in the P圜harm console, it would work. But, this is normal in a console-like environment. I believe JupyterLab automatically adds exec into your global scope, this is can lead to a lot of side-effects that you would rather not want. However, this is not a good way of doing things. Then, you can use l as a function outside of your exec scope. If you want the variables in exec to be added to global scope, then you need to do the following: exec('l = lambda x: x + 1', globals()) SolutionĮxecuting exec does not automatically put things into your global scope. What am I doing wrong? Why in JupyterLab and in P圜harm debug mode it works, but not when I run it P圜harm? This code runs just fine in Jupyter Lab, but results in a NameError: name 'l' is not defined exception when i run it through P圜harm.Īlso, when I use the debug mode in P圜harm, and try to evaluate l – it does show that this is a at 0x7fe604a13f28> The following toy example demonstrates my issue: import pandas as pdĭf = pd.DataFrame(dict(a=, b=))
I have the lambda in a str format, so I use the exec('l = lambda x: print(x)') function to turn it into a valid lambda and to assign it to a variable, but it throws the NameError: name 'l' is not defined exception when I try to use the lambda I use python3.6, and try to use lambda function which I load from.