Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74398 > unrolled thread

Newbie: unexpected indenting error

Started byMartin S <shieldfire@gmail.com>
First post2014-07-13 09:01 +0200
Last post2014-07-14 00:14 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Newbie: unexpected indenting error Martin S <shieldfire@gmail.com> - 2014-07-13 09:01 +0200
    Re: Newbie: unexpected indenting error Denis McMahon <denismfmcmahon@gmail.com> - 2014-07-14 00:14 +0000

#74398 — Newbie: unexpected indenting error

FromMartin S <shieldfire@gmail.com>
Date2014-07-13 09:01 +0200
SubjectNewbie: unexpected indenting error
Message-ID<mailman.11785.1405234880.18130.python-list@python.org>
While coding a rating calculator I am using a for-loop within if-elif-else.
When using the for-loop in the first if instance my editor accepts
this, but when using the same for-loop within the elif instance it
complain about "unexpected indent".

Like so:

def function(x):
   if rdiff >=500:
      for ....
         [do stuff]
   elif rdiff >=410:
       for ...                      <== unexpected indent
          [do other stuff]


What the...? What am I doing wrong?
(hopefully the indents translate; else def, if/elif, for and [dostuff]
are indented)

/Martin S
-- 
Regards,

Martin S

[toc] | [next] | [standalone]


#74407

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-07-14 00:14 +0000
Message-ID<lpv7cg$vb2$1@dont-email.me>
In reply to#74398
On Sun, 13 Jul 2014 09:01:12 +0200, Martin S wrote:

> While coding a rating calculator I am using a for-loop within
> if-elif-else.
> When using the for-loop in the first if instance my editor accepts this,
> but when using the same for-loop within the elif instance it complain
> about "unexpected indent".
> 
> Like so:
> 
> def function(x):
>    if rdiff >=500:
>       for ....
>          [do stuff]
>    elif rdiff >=410:
>        for ...                      <== unexpected indent
>           [do other stuff]
> 
> 
> What the...? What am I doing wrong?
> (hopefully the indents translate; else def, if/elif, for and [dostuff]
> are indented)

You seem to have posted what you believe is an equivalent structure to 
your code, rather than your actual code.

The structure you have posted looks fine, but it's not a runnable snippet 
that we can actually test.

Can you actually reproduce the problem in a single block of code that we 
can try and run ourselves?

For example, if you copy your "problem" function to a new file and edit 
the function def line and the code and lines after the for statements as 
follows, does the problem persist?

for rdiff in range( 450, 600, 100 ):
   if rdiff >=500:
      for i in range( 1, 3 ):
         print rdiff, i
   elif rdiff >=410:
      for i in range( 1, 3 ):
         print i, ridff

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web