Co_filename within notebooks

Hi, I need to know the co_filename of code objects created within jupyter notebook or jupyterlab if that is different, in particular I need to find a way to identify when a co_filename belongs to an object created within a notebook. Is there a way to do this consistently? I think that tempfile.tempdir should be useful as all the times I have tried both in linux and windows the file appears to be in that directory and so far the name is always {tempfile.tempdir}/ipykernel_{id1}/{id2}.py however I can’t figure out where this is set.

I would really appreaciate any help :slight_smile: