> To be honest, that's just made it even more weird :) You're creating > something in a local namespace that the Python compiler isn't aware > of.
Yes, I agree that retrieving the locals with PyEval_GetLocals and then sticking something in there on the C side is weird. I wouldn't say that the Python compiler is not aware of it though (I could ask my question purely in Python: how do I check in the scope of fun2 whether 'q' is available in the outer scope without actually using it). > I wonder, would a 'nonlocal q' declaration inside fun2 affect things > any? Yes, that pulls in 'q', but I would like to do that 'nonlocal q' on the C side. If I have to write 'nonlocal q' inside fun2 then I can also pull in 'q' using any other reference to 'q'. > Otherwise, maybe there's some completely different way to transfer > information around. Using locals in this way seems fraught with peril. There might very well be... Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list