(Solved) Local variables in scripted drivers

Is it possible to define local variables in a scripted driver?
E.g., I have a corrective shapekey whose value is driven by a bone. the driver is


1 if (+0.985972*X-0.028508*Y-0.145316*Z)< -1.982759 else -1*(+0.985972*X-0.028508*Y-0.145316*Z) - 0.982759 if (+0.985972*X-0.028508*Y-0.145316*Z)< -0.982759 else 0

where X,Y,Z are the Euler angles of the bone rotation. I would like to define a local variable x to simplify things to


x = (+0.985972*X-0.028508*Y-0.145316*Z)
1 if x< -1.982759 else -1*x - 0.982759 if x< -0.982759 else 0

However, the scripted expression can only be a single line. I tried to connect the two lines with a comma, but that is apparently illegal. Is there some other way to achieve this?

Solved the problem myself:

[1 if x< -1 else -1*x+0 if x< 0  else 0 for x in [+1.00327*X+0.029861*Y+0.140937*Z]][0]

Background: I’m importing files from DAZ Studio to Blender, and this type of code is needed for corrective shapekeys. In DS the shapekeys are driven by a single Euler angle, but in Blender the bones must be oriented differently, since the local Y axis must point from parent to child. Hence the driver becomes a mix of all three angles.

It is actually quite important to keep down the length of the expression, since scripted drivers must not exceed 256 characters.