[IronPython] Documentation/Example for Python expressions

Christian Schmidt christian2.schmidt at gmx.de
Wed Aug 26 21:33:05 CEST 2009


Hi Bruce,

thanks for your answer.

> How much python will you let your users execute?

Potentially everything that can be put into

ScriptEngine.CreateScriptSourceFromString(
      Expression, _SourceCodeKind.Expression_).Execute(ScriptScope)

> Are they just typing in formulas or are they accessing data structure?

Normally they type in simple formulas. But they are also allowed to type 
in formulas that access functions, properties of classes/objects/data 
structures and generators.

> The Python Tutorial http://docs.python.org/tutorial/index.html   or 
> http://www.diveintopython.org might be a good place to start, but if 
> they will not be allowed to forms loops, etc both might be too much.  

These are all nicely written introductions to python "programming". But 
that's too much: As Expression one can only enter "one-liners" - no 
structured programs, no function or class definitions, no control flow, 
no import statements ... simply no statements at all.

> Can you post an example if what someone would be entering with your program?

"Distance * AvgSpeed"

"Distance**0.9 if Distance > 0 else 5"

"sum([pos.time for pos in positions where pos.type = 7])"

"complicated_function1(a,b) + complicated_function2({ param1: c, param2: 
42 })"

where Distance, AvgSpeed, positions, a, b, c, ... are variables from the 
ScriptScope.





More information about the Ironpython-users mailing list