| 52 | |
| 53 | |
| 54 | def run_code(code, scope): |
| 55 | with use_scope(scope): |
| 56 | try: |
| 57 | """ |
| 58 | Remember that at module level, globals and locals are the same dictionary. |
| 59 | If exec gets two separate objects as globals and locals, |
| 60 | the code will be executed as if it were embedded in a class definition. |
| 61 | https://docs.python.org/3/library/functions.html#exec |
| 62 | """ |
| 63 | exec(code, session_local.globals) |
| 64 | except Exception as e: |
| 65 | toast('Exception occurred: "%s:%s"' % (type(e).__name__, e), color='error') |
| 66 | |
| 67 | |
| 68 | PRE_IMPORT = """from pywebio.input import * |