[Qgis-developer] (basic) python help

Martin Dobias wonder.sk at gmail.com
Thu Feb 9 04:41:05 EST 2012


On Thu, Feb 9, 2012 at 10:33 AM, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
> Hi all,
>
> I am dealing with the same problem for a while now, can someone tells me why
> these commands give a syntaxerror:
>
> eval("myvar ='3'")

There is a difference between evaluation (eval) and execution (exec)
of some code. When evaluating you only want a result of an expression.
When executing you actually run one or more statements in the current
context.

>>> eval("1+2")
3
>>> exec "x=1"
>>> x
1

Also note that exec is a statement (no parentheses) while eval is a
builtin function.

Martin


More information about the Qgis-developer mailing list