Checking Python Syntax without Executing

From IronPython Cookbook

(Difference between revisions)
MichaelFoord (Talk | contribs)
(New page: A useful snippet of code (actually shown from IronPython - but very easy to translate into C#) for checking the validity of Python code without actually executing it. <pre> engine = IronP...)
Newer edit →

Revision as of 13:49, 11 June 2009

A useful snippet of code (actually shown from IronPython - but very easy to translate into C#) for checking the validity of Python code without actually executing it.

engine = IronPython.Hosting.Python.CreateEngine()
source = engine.CreateScriptSourceFromString(text, SourceCodeKind.File)
errors = ErrorListener()
command = source.Compile(errors)
if command is None:
    # compilation failed


Back to Contents.

TOOLBOX
LANGUAGES