Citando Ian Witham <[EMAIL PROTECTED]>: 

> What version of Python arre you running Paulino? 
> 
> When I run your second snippet on 2.5 I get an error: 
> 
> >>> exp = "if i == 3 : continue" 
> >>> for i in range(5): 
>     exec(exp) 
>     print i, 
> 
> Traceback (most recent call last): 
>   File "<pyshell#17>", line 2, in <module> 
>     exec(exp) 
>   File "<string>", line 1 
> SyntaxError: 'continue' not properly in loop (<string>, line 1)
> 
> On 9/28/07, KENT JOHNSON <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote: 
> > Hello! 
> > 
> > Why doesn't the second code snipet, work like the first? 
> > 
> >>>> for i in range(5): 
> > ...    if i == 3 : continue
> > ...    print i, 
> > ... 
> > 0 1 2 4 
> > 
> >>>> exp = "if i == 3 : continue" 
> >>>> for i in range(5): 
> > ...    exec( exp ) 
> > ...    print i, 
> > ...
> > Traceback (most recent call last): 
> >    File "<input>", line 2, in <module> 
> >    File "<string>", line 1 
> > SyntaxError: 'continue' not properly in loop (<string>, line 1)
> 
> I think the code you pass to exec must be syntactically correct on its 
> own. It is parsed as if it were in a file by itself, then executed in 
> the local scope. 
> 
> Kent 
> _______________________________________________
> Tutor maillist  -  [EMAIL PROTECTED] 
> http://mail.python.org/mailman/listinfo/tutor[4]

  That's my question, the second snippet returns an error... 

  I have 2.5.1 also.  

  

Ligações:
---------
[1] mailto:[EMAIL PROTECTED]
[2] mailto:[EMAIL PROTECTED]
[3] mailto:[email protected]
[4] http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to