[issue6507] Enhance dis.dis to autocompile codestrings

Nick Coghlan report at bugs.python.org
Sat Jul 18 00:57:54 CEST 2009


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Copying my suggestion (minus examples) over from the python-ideas thread:

We could define it as trying the three modes in order (first 'eval',
then 'single', then 'exec') moving on to the next option if it raises
syntax error:

from dis import dis
def dis_str(source):
  modes = ('eval', 'single', 'exec')
  for mode in modes:
    try:
      c = compile(source, '', mode)
      break
    except SyntaxError:
      if mode is modes[-1]:
        raise
  return dis(c)

----------
nosy: +ncoghlan

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6507>
_______________________________________


More information about the Python-bugs-list mailing list