编辑器
import py_compile, tempfile, os # Create a temporary Python source file and compile it to bytecode with tempfile.NamedTemporaryFile('w', suffix='.py', delete=False) as f: f.write('x = 1\n') src = f.name py_compile.compile(src, doraise=True) print('OK') os.remove(src)
OK