vendredi 15 octobre 2021

How to replace code easily ? From VBA to Python

I have 1300 lines of code in VBA who look like this :

ElseIf InStr(LCase(A), LCase("B")) Then function = "* C"

I want to have something like this in Python :

elif (df2["A"]=="B") is True:
        return "* C" 

Only A, B and C change, do you know any way to do it ? My first idea was to use print and .format to something like this :

print("elif (df2['{}']=='{}') is True: return '{}' ".format(A, "B", "* C"))
                   

But that's not works to modify hundreds of lines

Aucun commentaire:

Enregistrer un commentaire