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 9147983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:08:40+00:00 2026-06-17T11:08:40+00:00

I’m trying to make my Python code look more readable. I read the style

  • 0

I’m trying to make my Python code look more readable. I read the style guide but I don’t know how to get something like this

x = foo(x);  # compute the value of the next prime number
             # that is larger than x  (foo is a really bad 
             # choice for this function's name) 

Or this

x = x + 1                 # Compensate for border
some other code           # some other comment

How do you wrap the comment and align them like this? You don’t just type a bunch of space, do you? What if I edited the code, do I have to realign the comments manually?

I’m using emacs as my editor.

  • 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-06-17T11:08:42+00:00Added an answer on June 17, 2026 at 11:08 am

    I don’t think you want this at all. Lattyware already explained the second case, but let’s look at the first:

    x = foo(x);  # compute the value of the next prime number
                 # that is larger than x  (foo is a really bad 
                 # choice for this function's name) 
    

    Comments that are too long to fit in-line can be turned into block comments above the code, like this:

    # compute the value of the next prime number that is larger than
    # x (foo is a really bad choice for this function's name)
    x = foo(x);
    

    That seems more readable than the right-aligned comments. It also gives you more room. And it’s definitely easier with emacs (just type the whole thing and meta-Q it). And, quoting Inline Comments in PEP 8:

    Use inline comments sparingly.

    An inline comment is a comment on the same line as a statement.

    This is the very beginning of the style guide for inline comments, and it implies pretty strongly that if you’re trying to write more than you can fit on the same line, you should be using a block comment instead.

    Also, while we’re talking about PEP 8:

    • "Comments should be complete sentences." Your first comment needs periods. (Yes, it also says "If a comment is short, the period at the end can be omitted", but you have a 3-line 2-sentence comment, so that doesn’t apply here.)
    • " If a comment is a phrase or sentence, its first word should be capitalized". So, capitalize "Compute" (but not "foo", because that’s an identifier).
    • Don’t add a comment that the function’s name is bad, just rename the function.
    • Get rid of that semicolon.

    So:

    # Compute the value of the next prime number that is larger than x.
    x = next_larger_prime(x)
    

    But once you’ve done that, you don’t even need the comment.

    And in fact, that’s pretty common. When you find yourself wondering how to break the style guidelines on commenting, you should probably instead by asking how to reorganize the code so it doesn’t need all those comments. It’s not always possible, but it’s usually worth at least trying.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.