[Qgis-developer] (basic) python help

Denis Rouzaud denis.rouzaud at gmail.com
Thu Feb 9 04:50:27 EST 2012


Hi Martin, Hi Nathan,

Thank you both for your replies.

The solution was effectively using exec. The difference is not very 
straightforward but I think I got it!

Btw, I am using this to save list in a layer custom property, and the 
way I found is playing with repr and eval exec.

Thanks again! You save me a lot of time, I was not looking in the right 
direction!

Denis


On 02/09/2012 10:41 AM, Martin Dobias wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120209/ac45867b/attachment.html


More information about the Qgis-developer mailing list