Comments within a line

Discussion in 'Python' started by Edward Diener, Jul 31, 2004.

  1. Has there ever been any discussion of adding comments notation to Python,
    such as C++'s /* */, which could occur in the middle of a line or span
    multiple lines ? I would like to see it as a more elegant solution for
    quickly commenting out code. I am aware of the """ """ technique around
    multiple lines but even that seems a poor hack. A comment that could enclose
    any sequence of characters would be most welcome.
     
    Edward Diener, Jul 31, 2004
    #1
    1. Advertising

  2. "Edward Diener" <> writes:

    > Has there ever been any discussion of adding comments notation to Python,
    > such as C++'s /* */, which could occur in the middle of a line or span
    > multiple lines ? I would like to see it as a more elegant solution for
    > quickly commenting out code.


    In C/C++, you wouldn't use /* */ for commenting out code, since it
    would collide with any comment already there (comments can't be
    nested). Instead, the usual way is using #if 0 ... #endif.

    You can use "if 0:" with python as well, but of course, you'd have to
    indent the entire commented-out block. With most editors, this isn't
    much of a problem. I usually use some smaller, "odd" indent than
    usual to have an indicication later where the block ends.

    - Heike
     
    Heike C. Zimmerer, Jul 31, 2004
    #2
    1. Advertising

  3. [Heike C. Zimmerer]
    > "Edward Diener" <> writes:


    > > Has there ever been any discussion of adding comments notation to
    > > Python, such as C++'s /* */, which could occur in the middle of
    > > a line or span multiple lines ? I would like to see it as a more
    > > elegant solution for quickly commenting out code.


    > You can use "if 0:" with python as well, but of course, you'd have
    > to indent the entire commented-out block. With most editors, this
    > isn't much of a problem. I usually use some smaller, "odd" indent
    > than usual to have an indicication later where the block ends.


    One common trick is to embed a region to comment within triple quotes
    (for example, you write ''' (three single quotes) at the beginning of
    the text on the first line of your block, and the same after the end of
    the text on the last line of your block. I've even read that strings as
    statements are optimised out (if not in doc-string position).

    I do not use this trick myself. With any reasonable editor, it is very
    easy to comment or uncomment a bunch of lines in a simple operation, and
    this is neater.

    --
    Fran├žois Pinard http://www.iro.umontreal.ca/~pinard
     
    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Jul 31, 2004
    #3
  4. Heike C. Zimmerer wrote:
    > "Edward Diener" <> writes:
    >
    >> Has there ever been any discussion of adding comments notation to
    >> Python, such as C++'s /* */, which could occur in the middle of a
    >> line or span multiple lines ? I would like to see it as a more
    >> elegant solution for quickly commenting out code.

    >
    > In C/C++, you wouldn't use /* */ for commenting out code, since it
    > would collide with any comment already there (comments can't be
    > nested).


    That's true but many times it will not, especially if one comments out code
    within a line, or if one is using // liberally also.

    > Instead, the usual way is using #if 0 ... #endif.


    Yes, this is the usual method in C++ which I often use, but Python has no
    preprocessor.

    >
    > You can use "if 0:" with python as well, but of course, you'd have to
    > indent the entire commented-out block. With most editors, this isn't
    > much of a problem. I usually use some smaller, "odd" indent than
    > usual to have an indicication later where the block ends.


    Decent idea. Still some sort of multi-line comment notation in Python would
    be preferable.
     
    Edward Diener, Jul 31, 2004
    #4
  5. Edward Diener

    Dan Bishop Guest

    "Edward Diener" <> wrote in message news:<B4OOc.21170$>...
    > Heike C. Zimmerer wrote:
    > > "Edward Diener" <> writes:
    > >
    > >> Has there ever been any discussion of adding comments notation to
    > >> Python, such as C++'s /* */, which could occur in the middle of a
    > >> line or span multiple lines ? I would like to see it as a more
    > >> elegant solution for quickly commenting out code.

    > >
    > > In C/C++, you wouldn't use /* */ for commenting out code, since it
    > > would collide with any comment already there (comments can't be
    > > nested).

    >
    > That's true but many times it will not, especially if one comments out code
    > within a line, or if one is using // liberally also.


    I once saw someone write C code that commented out code with /* */
    comments, and then decided he needed to temporarily use that code
    again, so he commented out the /* and */ with //'s.
     
    Dan Bishop, Aug 1, 2004
    #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. Hugo
    Replies:
    10
    Views:
    1,345
    Matt Humphrey
    Oct 18, 2004
  2. Replies:
    0
    Views:
    1,157
  3. Monk
    Replies:
    10
    Views:
    1,502
    Michael Wojcik
    Apr 20, 2005
  4. kaushikshome
    Replies:
    4
    Views:
    796
    kaushikshome
    Sep 10, 2006
  5. Replies:
    4
    Views:
    634
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page