Well, I see why you're doing this and I can see why it's troubling. I do concur that using MEL commands in expressions must be done minimally, but keyframe -q -eval explicitly doesn't touch the dependency graph (according to the docs) so you're probably safe doing this.
A couple of things; first off, you're either building this expression node by hand or you're doing it by assembling a string in a MEL script. In either of these cases, at the time you build the expression you should know the name of the object that's being used for the expression's default inputs, so you can put that object's explicit name into the expression.
For example, I can use this MEL script to make a hundred spheres oscillate:
for ($count = 0; $count < 100; $count++)
{
string $mySphereName[] = `sphere`;
float $startY = rand(10);
move (rand(10), $startY, rand(10);
expression -s ($mySphereName[0] + ".ty = " + $startY + " + sin(time);");
}
This creates a hundred expressions, one per sphere, each connected to one sphere. This has the advantage that each expression is individually cacheable, unlike an expression that loops over several.
By building the expression as a string and assigning it with the "expression" command, I'm putting the actual relevant node name into the expression at creation time rather than relying on figuring out the name of the affected object at runtime.
However, if you really wanted to, if you had a variable containing the name of the node for which you wanted to evaluate keys, you could do this:
float $test[] = keyframe -time $time -q -eval ($nodeName + "\_translateY")
;
By putting the string operation in parentheses it will work. I just tested it.
-- Mark