why it is invalid syntax?
cokofreedom at gmail.com
cokofreedom at gmail.com
Thu Nov 22 11:59:53 EST 2007
On Nov 22, 5:46 pm, Stargaming <stargam... at gmail.com> wrote:
> On Thu, 22 Nov 2007 03:24:48 -0800, cokofreedom wrote:
> > On Nov 22, 10:58 am, "Guilherme Polo" <ggp... at gmail.com> wrote:
> >> 2007/11/22, Stef Mientki <S.Mientki-nos... at mailbox.kun.nl>:
>
> >> > alf wrote:
> >> > > Hi,
>
> >> > > I wonder why it is an invalid syntax:
>
> >> > > >>> if 1: if 1: if 1: print 1
> >> > > File "<stdin>", line 1
> >> > > if 1: if 1: if 1: print 1
>
> >> > > or
>
> >> > > >>> if 1: for i in range(10): print i
> >> > > File "<stdin>", line 1
> >> > > if 1: for i in range(10): print i
>
> >> > > I would expect one could nest :
>
> >> > Although I agree it might be quit unreadable for normal programmers,
> >> > people who are used to writing math formula, (i.e. MatLab), this is
> >> > not true.
>
> >> > Here another interesting one, that is accepted:
>
> >> > self.nodes.extend ( [ ONode(shape,n,self) \
> >> > for n in range(shape.Parent.N_Outputs)
> >> > \ if shape.Type_Outputs[n] == type ] )
>
> >> That is a list comprehension
>
> >> > cheers,
> >> > Stef
> >> > --
> >> >http://mail.python.org/mailman/listinfo/python-list
>
> >> --
> >> -- Guilherme H. Polo Goncalves
>
> > So acceptable usage (though disgusting :P) would be
>
> > while 1: print 'hello'; print 'goodbye'; exec(rm -rf *)
>
> Nope::
>
> exec(rm -rf *)
> ^
> SyntaxError: invalid syntax
>
> Even the syntactically correct ``exec("rm -rf *")`` would make your
> computer explode. Should we introduce this as a shortcut to `break`? ;-)
>
> SCNR,
> stargaming
Haha, you are correct. I was tempted to actually trial and error the
code too much...
I feel it is an important thing to present to a new user however, much
like the infinite "alert message" because of their infinite loop.
More information about the Python-list
mailing list