hello,<br><br>I want to use Python to give users the possibility to analyze data and create their custom reports.<br>So I want a very simple language definition for the user, like :<br>- the script must be case-insensitive<br>
- "user-words" are automatically translated into function names<br>- users strings, should be entered without the quotes, so these strings will be defined as names<br><br>Now the code below seems to fulfill these wishes (in real life, the number of dummy procedures is about 40),<br>
but I always wonder if there's an easier way to achieve the same effect.<br><br>thanks,<br>Stef Mientki<br><br>def _Meting ( Nr, Test, Subschaal ) :<br>    """<br>    here the real calculation will be done<br>
    """<br>    global Result<br>    Result += str ( Nr ) + ': ' + Test + '/' + Subschaal + '\n'<br><br># Dummy procedures to add the extra argument "Nr"<br>def _Meting_1 ( *args, **kwargs ) :<br>
    _Meting ( 1, *args, **kwargs )<br><br>def _Meting_2 ( *args, **kwargs ) :<br>    _Meting ( 2, *args, **kwargs )<br># end of dummy procedures<br><br># These are names definied by the user, retrieved from a database<br>
Meting_Namen = {}<br>Meting_Namen [1] = 'Voormeting'<br>Meting_Namen [2] = 'Nameting'<br><br># Make the user definied names available in the current namespace<br>for Meting in Meting_Namen :<br>    Name = Meting_Namen [ Meting ].lower ()   # 'voormeting'<br>
    exec ( Name + '= _Meting_' + str ( Meting ) )<br><br># Another set of strings should be available as names (also retrieved from a database)<br>test1 = 'Test1'<br>fat = 'Fat'<br><br># Storage for the results<br>
Result = ''<br><br># Script entered by the user<br>Code = "Voormeting ( Test1, fat )"<br><br># execute the user script in the current namespace  (make code case-insensitive)<br>exec ( Code.lower () )<br>
<br># for test print the result<br>print Result<br><br><br>