lundi 29 mars 2021

bind action to if-condition in python [closed]

I'm working with a special python-interpreter (not manipulatable) who converts my python-script A, which is a normal python script with if-conditions, classes, functions usw. into a python-script B, which only consists out of defined functions with absolute values. For example:

Script A

s = 30
x = True
TranslatedFunction("20");
if x:
    TranslatedFunction(s)
TranslatedFunction("40");

This script will be converted into Script B:

TranslatedFunction("20");
TranslatedFunction("30");
TranslatedFunction("40");

As you see, the interpreter goes through the condition and checks if its true, when it is, it will write the TranslatedFunction(s) with the value of s into Script B. I can't change this behaivour. I also can't access the variable x or s.

So far so good. Now, I need to know in script B, where the if-condition in script A was. I could to something like this:

Script A

s = 30
x = True
TranslatedFunction("20");
if x:
    TranslatedFunction("startif")
    TranslatedFunction(s)
    TranslatedFunction("endif")
TranslatedFunction("40");

which will result in:

TranslatedFunction("20");
TranslatedFunction("startif");
TranslatedFunction("30");
TranslatedFunction("endif");
TranslatedFunction("40");

That would be enough to work with (after the translation from script A to script B, I got a postprocessor, which will translate script B in another language). But I don't want to mark the if-conditions everytime. Is there a better way to call a function, or do something, everytime an if-condition starts and ends? And would there be also something for loops?

Update

I'm working with RoboDK. A Program to simulate roboters and generate a roboterprogram out of it.

Thanks.

Aucun commentaire:

Enregistrer un commentaire