473,233 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

why it is invalid syntax?

alf
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 :
--
alf
Nov 22 '07 #1
7 3898
On Thu, 22 Nov 2007 00:00:16 -0600, alf wrote:
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 :
It's quite unreadable and if this would be allowed you would have to
introduce a special rule to forbid ``else``, ``except`` and ``finally``
because it can lead to ambiguities. To which ``if`` does the ``else``
belong to here? ::

if 1: print 1 if: 1 print 1 else: print 1

Ciao,
Marc 'BlackJack' Rintsch
Nov 22 '07 #2
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 ] )

cheers,
Stef
Nov 22 '07 #3
2007/11/22, Stef Mientki <S.**************@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
Nov 22 '07 #4
On Nov 22, 10:58 am, "Guilherme Polo" <ggp...@gmail.comwrote:
2007/11/22, Stef Mientki <S.Mientki-nos...@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 *)
Nov 22 '07 #5
On Thu, Nov 22, 2007 at 06:47:33AM +0000, Marc 'BlackJack' Rintsch wrote regarding Re: why it is invalid syntax?:
>
It's quite unreadable and if this would be allowed you would have to
introduce a special rule to forbid ``else``, ``except`` and ``finally``
because it can lead to ambiguities. To which ``if`` does the ``else``
belong to here? ::

if 1: print 1 if: 1 print 1 else: print 1

Ciao,
Marc 'BlackJack' Rintsch
I don't reckon in matters much. Your output will be:

1
1

;)

No, actually on second inspection your output will be:

File "<stdin>", line 1
if 1: print 1 if: 1 print 1 else: print 1
^
SyntaxError: invalid syntax

But it's a good point.

Cheers,
Cliff
Nov 22 '07 #6
On Thu, 22 Nov 2007 03:24:48 -0800, cokofreedom wrote:
On Nov 22, 10:58 am, "Guilherme Polo" <ggp...@gmail.comwrote:
>2007/11/22, Stef Mientki <S.Mientki-nos...@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
Nov 22 '07 #7
On Nov 22, 5:46 pm, Stargaming <stargam...@gmail.comwrote:
On Thu, 22 Nov 2007 03:24:48 -0800, cokofreedom wrote:
On Nov 22, 10:58 am, "Guilherme Polo" <ggp...@gmail.comwrote:
2007/11/22, Stef Mientki <S.Mientki-nos...@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.
Nov 22 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bradley Kite | last post by:
Hi all. I'm trying to diagnose/solve a problem with internet explorer, whereby sometimes the form submits, and other times IE produces an 'invalid syntax' error. First, I have a form, and...
5
by: DIBS | last post by:
I'm new to Python and I don't understand what I'm doing wrong. I'm running windows xp. In the command line window, I type: Python Sudoku.py and I get the response" SyntaxError: invalid...
5
by: chrisstankevitz | last post by:
Hi, Q1: Is there a way to make a template function that works only for specific types which produces a compiler error if used with an invalid type? Q2: If not, how do people deal with this...
10
by: ronrsr | last post by:
no matter where I place this imported file,the statement after it in the main program gets a syntax error, regardless of the syntax. I think I may have changed something in this file, but I'm...
6
by: Nathan Pinno | last post by:
Why does my compiler say invalid syntax and then highlight the quotation marks in the following code: # This program is to find primes. primes = import math import gmpy while 1: run =...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.