> That and the arguments they accept are different.  evalDeferred takes a
> string, executeDeferred accepts a callable and any arguments you would like
> to pass to the callable.  executeDeferred works in batch mode only if you
> use the pymel implementation of it.
>

vs.

That's a python thing. There's a lot of discussion on eval vs exec as
> they're a pair of low level calls that end up exposed together. You also
> run into it a lot when embedding python. The biggest difference is return
> value.


As Tony points out in the first quoted section above, the difference
between evalDeferred and executeDeferred has to do with the old mel command
vs the new python function.  logically, since the former is a mel command,
and the latter a python function that takes a python object and not a
string, the difference is not related to the difference between eval and
exec in python. sorry Brad, it was a good guess, though :)

on the topic of eval vs exec: in brief, eval evaluates a python
"expression", which is anything that can be executed on a single line and
stored in a variable:

    "1 + 1"
    "'me' if name == 'chad' else 'you'"
    "answer1 or answer2 and answer3"

of course, the variables referenced need to exist in the current scope, or
you can pass your own globals and locals.

exec can execute many lines of complete python code and is not limited to
just expressions. it can even execute the contents of an entire module,
though there is a shortcut for the latter called execfile.  this is
actually how python plugins in maya are loaded: they are not imported.

exec should not be used as a crutch to avoid learning how to do things
pythonically.  e.g. don't do this:

    exec "import %s" % module_name

do this:

    __import__(module_name, globals(), locals(), [], -1)

or use the imp module.

hope that helps.

chad.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAGq9Q7GwVkk7vCGZg9BS8D-9ZxoVPxg1qc8Qsjrnsgc0_smF4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to