⚠️ 最后一站:真的跑一次

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

把编译好的那个 code 对象真的执行一次:

import ast, io, tokenize

LINE = 'print("hi")'

def toks(src):
    skip = (tokenize.NEWLINE, tokenize.NL, tokenize.ENDMARKER,
            tokenize.INDENT, tokenize.DEDENT)
    return [t.string for t in tokenize.generate_tokens(io.StringIO(src).readline)
            if t.type not in skip]

code = compile(LINE, "<s>", "exec")
exec(code, {"print": print})
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论