[IronPython] Documentation/Example for Python expressions

Michael Foord fuzzyman at voidspace.org.uk
Wed Aug 26 21:36:37 CEST 2009


Christian Schmidt wrote:
> 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.

Unfortunately I don't think such a documentation exists (not that I'm 
aware of but the internets is a big place). I wish it did - and if you 
write one then please make it public.

The Python grammar is a good place to get the definitive syntax allowed 
in expressions, at least if you can read BNF.

Michael

>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list