(code, strip_indent=4)
| 10 | |
| 11 | |
| 12 | def code_block(code, strip_indent=4): |
| 13 | if strip_indent: |
| 14 | lines = ( |
| 15 | i[strip_indent:] if (i[:strip_indent] == ' ' * strip_indent) else i |
| 16 | for i in code.splitlines() |
| 17 | ) |
| 18 | code = '\n'.join(lines) |
| 19 | code = code.strip('\n') |
| 20 | |
| 21 | def run_code(code, scope): |
| 22 | with use_scope(scope): |
| 23 | exec(code, globals()) |
| 24 | |
| 25 | with use_scope() as scope: |
| 26 | put_code(code, 'python') |
| 27 | put_buttons([{'label': t('Run', '运行'), 'value': '', 'color': 'success'}], |
| 28 | onclick=[partial(run_code, code=code, scope=scope)], small=True) |
| 29 | |
| 30 | |
| 31 | async def main(): |
no test coverage detected
searching dependent graphs…