[Tutor] exec sintax error or bug?

paulino1 at sapo.pt paulino1 at sapo.pt
Fri Sep 28 01:14:44 CEST 2007



  Citando Ian Witham <witham.ian at gmail.com>: 

> 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 <kent37 at tds.net[1]> wrote: paulino1 at sapo.pt[2] 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  -  Tutor at python.org[3] 
> 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:kent37 at tds.net
[2] mailto:paulino1 at sapo.pt
[3] mailto:Tutor at python.org
[4] http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070928/8f55a767/attachment-0001.htm 


More information about the Tutor mailing list