# Exec() scope in a callback

**URL:** <https://community.plotly.com/t/exec-scope-in-a-callback/74819>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [April 28, 2023, 1:54pm UTC](https://community.plotly.com/t/exec-scope-in-a-callback/74819 "2023-04-28T13:54:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yrou](https://avatars.discourse-cdn.com/v4/letter/y/ce7236/32.png) [@yrou](https://community.plotly.com/u/yrou)\
**Post date:** [April 28, 2023, 1:54pm UTC](https://community.plotly.com/t/exec-scope-in-a-callback/74819/1 "2023-04-28T13:54:53Z")

</div>

Hi All

I have a problem to access variable created wth a callback but executed with python exec() command. I pass the globals() dictionary and the locals() dictionary to the exec() fonction, but get a KeyError when a try to access a variable created during the execution. I get the KeyError even if look for this variable in the globals() dictionary or the locals() dictionary. i reasonably think that I should find the created variable in the local dictionary.  
Here is an extract of the code

exec(‘’’

image = Image.open(figfile)  
output = html.Img(src=image, width=600, height=1200)  
… , globals(), locals())

dict\_locals = locals()  
output = dict\_locals[‘output’]  
return output

The fact is that when I execute similar code outside a dash application, it runs fine.

Thanks for a help/
