Having trouble making Python communicate with MEL

So I’m pretty new at all this, so this might be an incredibly easy question. What I’m trying to do is write a Python script that (among many other things), allows you to specify the location of a MEL script that it will then run. However I’m having trouble using the maya.mel.eval command.

Namely, you can’t use the source command to grab a MEL script with a variable. It has to be

source “file location” ;

And if you want to use a variable you have to do it using an eval. Easy.

string $scriptpath = “file location” ;
string $melSource = (“source “”+$scriptpath+”" ;") ;
eval $melSource ;

So this works totally fine in MEL. However, Python seems to be having trouble doing it.

When I try

maya.mel.eval(‘string $melSource = (“source “”+$scriptpath+”" ;") ;’)

I get back that it tried to run

// Error: string $melSource = (“source “”+$scriptpath+”" ;") ; //

Which is NOT what I wrote. You can see that the integral \ are missing, which means the MEL script won’t work. Why would python be removing those before running the MEL script? Can someone help me out with a way around this?

what would be wrong with

scriptpath = 'pathto.mel'
mm.eval('source "'+scriptpath+'" ;')

How do you put a quote in quotes? In Mel, you use the escape sequence " to indicate that the character following the \ should be treated as a plain character instead of a special syntax character.

I know you know that – it’s obvious from your mel.

The problem is the exact same thing applies in Python, even when you use the single quote instead of the double quote as your string boundaries. So those escape sequences are getting evaluated twice – once by python and once by mel. You need to double up is all.

maya.mel.eval(‘string $melSource = (“source \”"+$scriptpath+"\" ;") ;’)

[QUOTE=Bronwen;20546]How do you put a quote in quotes? In Mel, you use the escape sequence " to indicate that the character following the \ should be treated as a plain character instead of a special syntax character.

I know you know that – it’s obvious from your mel.

The problem is the exact same thing applies in Python, even when you use the single quote instead of the double quote as your string boundaries. So those escape sequences are getting evaluated twice – once by python and once by mel. You need to double up is all.

maya.mel.eval(‘string $melSource = (“source \”"+$scriptpath+"\" ;") ;’)[/QUOTE]

Aha! I suspected it might be something simple like that. Thanks for the help!