Re: Problem with the "for" loop syntax

Discussion in 'Python' started by Joshua Landau, Jun 20, 2013.

  1. On 20 June 2013 04:11, Cameron Simpson <> wrote:
    > Also, opening-and-not-closing a set of brackets is almost the only
    > way in Python to make this kind of error (syntax at one line, actual
    > mistake far before).
    >
    > See if your editor has a show-the-matching-bracket mode.

    <snip>
    > If you suspect you failed to close a bracket, one approach is to
    > go _below_ the syntax error (or right on it) and type a closing
    > bracket. Then see where the editor thinks the opening one is.


    Thanks for that, that's quite an ingenious technique.
    Joshua Landau, Jun 20, 2013
    #1
    1. Advertising

  2. Joshua Landau

    Neil Cerutti Guest

    On 2013-06-20, Joshua Landau <> wrote:
    > On 20 June 2013 04:11, Cameron Simpson <> wrote:
    >> Also, opening-and-not-closing a set of brackets is almost the
    >> only way in Python to make this kind of error (syntax at one
    >> line, actual mistake far before).
    >>
    >> See if your editor has a show-the-matching-bracket mode.
    >> If you suspect you failed to close a bracket, one approach is
    >> to go _below_ the syntax error (or right on it) and type a
    >> closing bracket. Then see where the editor thinks the opening
    >> one is.

    >
    > Thanks for that, that's quite an ingenious technique.


    The auto-indent feature of Vim catches this type of syntax error,
    and I imagine other good autoindent support will do the same.
    After I press enter and the following line's indent isn't what I
    expect, it is nearly always due to a missing bracket, quote or
    colon.

    So if you press enter and the autoindent is unexpected, don't
    just press space or backspace to fix it. It's usually a sign of
    an earlier syntax error, so look for that first.

    --
    Neil Cerutti
    Neil Cerutti, Jun 20, 2013
    #2
    1. Advertising

  3. On Thu, Jun 20, 2013 at 11:55 PM, Neil Cerutti <> wrote:
    > On 2013-06-20, Joshua Landau <> wrote:
    >> On 20 June 2013 04:11, Cameron Simpson <> wrote:
    >>> Also, opening-and-not-closing a set of brackets is almost the
    >>> only way in Python to make this kind of error (syntax at one
    >>> line, actual mistake far before).
    >>>
    >>> See if your editor has a show-the-matching-bracket mode.
    >>> If you suspect you failed to close a bracket, one approach is
    >>> to go _below_ the syntax error (or right on it) and type a
    >>> closing bracket. Then see where the editor thinks the opening
    >>> one is.

    >>
    >> Thanks for that, that's quite an ingenious technique.

    >
    > The auto-indent feature of Vim catches this type of syntax error,
    > and I imagine other good autoindent support will do the same.
    > After I press enter and the following line's indent isn't what I
    > expect, it is nearly always due to a missing bracket, quote or
    > colon.
    >
    > So if you press enter and the autoindent is unexpected, don't
    > just press space or backspace to fix it. It's usually a sign of
    > an earlier syntax error, so look for that first.


    Yes, though editors (like everything else!) can be buggy - SciTE, for
    instance, has a bug with handling two adjacent braces in C code:

    void dummy_function() {}
    //SciTE will indent after that line

    But autoindentation is a *hugely* valuable feature, because it gives
    INSTANT feedback. You hit enter, the line is indented, you expected no
    indent, problem found. And I've even used it as a means of probing -
    if there's a problem in this area somewhere, I just go to the middle
    of the area, hit enter to insert a blank line, and see if the
    indentation is wrong. If it is, the problem's in the top half, else
    the problem's in the bottom half. That is: The problem is in the
    top-if-indentation-wrong-else-bottom half, using Python's ternary
    syntax. Or the (indentation-wrong? top: bottom) half, in C notation.
    Or... okay, I'll stop now.

    ChrisA
    Chris Angelico, Jun 20, 2013
    #3
  4. On 20Jun2013 13:55, Neil Cerutti <> wrote:
    | On 2013-06-20, Joshua Landau <> wrote:
    | > On 20 June 2013 04:11, Cameron Simpson <> wrote:
    | >> Also, opening-and-not-closing a set of brackets is almost the
    | >> only way in Python to make this kind of error (syntax at one
    | >> line, actual mistake far before).
    | >>
    | >> See if your editor has a show-the-matching-bracket mode.
    | >> If you suspect you failed to close a bracket, one approach is
    | >> to go _below_ the syntax error (or right on it) and type a
    | >> closing bracket. Then see where the editor thinks the opening
    | >> one is.
    | >
    | > Thanks for that, that's quite an ingenious technique.
    |
    | The auto-indent feature of Vim catches this type of syntax error,
    | and I imagine other good autoindent support will do the same.

    Interesting. I use autoindent but grew up with it for prose.
    I hadn't realised vim's support inderstaood python indentation.
    I'll have to pay more attention...
    --
    Cameron Simpson <>

    Do I have it all? Yes.
    Do I want more? Yeah, sure. - Demi Moore
    Cameron Simpson, Jun 20, 2013
    #4
  5. Joshua Landau

    Neil Cerutti Guest

    On 2013-06-20, Cameron Simpson <> wrote:
    > On 20Jun2013 13:55, Neil Cerutti <> wrote:
    >| On 2013-06-20, Joshua Landau <> wrote:
    >| > On 20 June 2013 04:11, Cameron Simpson <> wrote:
    >| >> Also, opening-and-not-closing a set of brackets is almost the
    >| >> only way in Python to make this kind of error (syntax at one
    >| >> line, actual mistake far before).
    >| >>
    >| >> See if your editor has a show-the-matching-bracket mode.
    >| >> If you suspect you failed to close a bracket, one approach is
    >| >> to go _below_ the syntax error (or right on it) and type a
    >| >> closing bracket. Then see where the editor thinks the opening
    >| >> one is.
    >| >
    >| > Thanks for that, that's quite an ingenious technique.
    >|
    >| The auto-indent feature of Vim catches this type of syntax error,
    >| and I imagine other good autoindent support will do the same.
    >
    > Interesting. I use autoindent but grew up with it for prose. I
    > hadn't realised vim's support inderstaood python indentation.
    > I'll have to pay more attention...


    A standard Vim install autoindents Python tolerably well if
    you've set filetype=python. If you've got a baked-in Python
    interpreter you can get even more bells and whistles. The
    standard executable installs I could find don't support Python 3,
    so I haven't seen all the great stuff I'm missing.

    --
    Neil Cerutti
    Neil Cerutti, Jun 21, 2013
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Isaac Won
    Replies:
    9
    Views:
    352
    Ulrich Eckhardt
    Mar 4, 2013
  2. arturo balbuena

    Problem with the "for" loop syntax

    arturo balbuena, Jun 19, 2013, in forum: Python
    Replies:
    8
    Views:
    130
    Chris Angelico
    Jun 20, 2013
  3. Cameron Simpson

    Re: Problem with the "for" loop syntax

    Cameron Simpson, Jun 20, 2013, in forum: Python
    Replies:
    0
    Views:
    108
    Cameron Simpson
    Jun 20, 2013
  4. Oscar Benjamin

    Re: Problem with the "for" loop syntax

    Oscar Benjamin, Jun 20, 2013, in forum: Python
    Replies:
    0
    Views:
    94
    Oscar Benjamin
    Jun 20, 2013
  5. Cameron Simpson

    Re: Problem with the "for" loop syntax

    Cameron Simpson, Jun 20, 2013, in forum: Python
    Replies:
    0
    Views:
    90
    Cameron Simpson
    Jun 20, 2013
Loading...

Share This Page