Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:11:49+00:00 2026-05-27T10:11:49+00:00

Why is there a different rule for blank lines in Python between the interactive

  • 0

Why is there a different rule for blank lines in Python between the interactive prompt and when the program is run from shell as an executable?

Since blank lines are ignored, I enjoy using them abundantly. However, in the interactive prompt, a blank line is used to terminate a loop. Thus, I keep running into indentation errors when I paste a chunk of code into the interactive prompt as I would have blank lines throughout my loops. Consequently, this makes the interactive debugging/development process somewhat tedious. Putting a # instead of blank line helps, but I like my blank lines.

Even more annoying is different behavior between prompts (e.g., the Python shell and IPython). Where the Python interactive prompt would give me an error where I expect it, IPython would keep executing the indented code as if it was not part of loop without complaining.

I feel there is an easy solution out there, but I’m not aware of it. I am using vi for editing and Python/IPython prompts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:11:50+00:00Added an answer on May 27, 2026 at 10:11 am

    PEP 8 defines how blank lines should be used:

    Blank Lines

    Separate top-level function and class definitions with two blank lines.
    Method definitions inside a class are separated by a single blank line.

    Extra blank lines may be used (sparingly) to separate groups of related
    functions. Blank lines may be omitted between a bunch of related
    one-liners (e.g. a set of dummy implementations).

    Use blank lines in functions, sparingly, to indicate logical sections.

    Python accepts the control-L (i.e. ^L) form feed character as whitespace;
    Many tools treat these characters as page separators, so you may use them
    to separate pages of related sections of your file. Note, some editors
    and web-based code viewers may not recognize control-L as a form feed
    and will show another glyph in its place.

    If you stick to the PEP, the only instance in which blank lines might generate problems in the interactive console are "blank lines in functions to indicate logical sections", I believe.

    You can circumvent the problem like this though:

    >>> def a():
    ...     print 'foo'\
    ...
    ...     print 'bar'
    ...
    >>> a()
    foo
    bar
    

    Note that using \ instead of # as you suggest in your question leaves the blank line… blank (as the \ goes on the previous line).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a general rule for referencing a type from a different namespace. Do
is there any different in Connection string between SQL server Authentication and Windows Authentication
In javascript, is there any different between these two: // call MyFunction normal way
Greetings, Is there a different between using Ajax and jquery to do input valuation
The proccess I've started has a different terminal id from tty result. Is there
Are there different limitations as to how many connections (sockets) that can be created
I'm sure there are different approaches to this problem, and I can think of
In x86 GNU Assembler there are different suffixes for memory related operations. E.g.: movb,
Is this fine or is there a different way? <a href=Http://<%=Html.Encode(Model.Website)%>><%=Html.Encode(Model.Website??)%></a>
I have a collection of MDI forms, where there are different objects (Form1,Form2 etc).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.