FAQ
I've been using Python for quite some time now, and I'm a bit stumped.

Does it really not have a multi-line comment? I think I must just be
missing something simple and stupid.

Thanks in advance.

Doug Tolton

Search Discussions

  • Skip Montanaro at Aug 11, 2003 at 7:17 pm
    Doug> I've been using Python for quite some time now, and I'm a bit
    Doug> stumped. Does it really not have a multi-line comment? I think I
    Doug> must just be missing something simple and stupid.

    Nope, no multi-line comment. The python-mode package which is available for
    Emacs and XEmacs supports commenting a block of text. You can also use
    triple-quoted strings:

    """
    This is a multi-
    line
    comment
    (sort of)
    """

    It gets evaluated but immediately popped from the execution stack.

    Skip
  • Tim Peters at Aug 11, 2003 at 8:24 pm
    [Skip Montanaro]
    Nope, no multi-line comment. The python-mode package which is
    available for Emacs and XEmacs supports commenting a block of text.
    You can also use triple-quoted strings:

    """
    This is a multi-
    line
    comment
    (sort of)
    """

    It gets evaluated but immediately popped from the execution stack.
    One of the previous times this came up, Guido suggested that the compiler
    could be changed to optimize away string expressions that aren't docstrings.
    It was then my task to fire up the time machine so that I could report that
    the compiler already did. It still does <wink>. That is, it doesn't get
    evaluated or popped -- it's not in the compiled code at all, so is exactly
    like a comment in that respect.
  • Aahz at Aug 11, 2003 at 7:30 pm
    In article <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3 at 4ax.com>,
    Doug Tolton wrote:
    Does it really not have a multi-line comment? I think I must just be
    missing something simple and stupid.
    '''
    Most people use triple-quoted strings
    for multi-line comments.
    '''
    --
    Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

    This is Python. We don't care much about theory, except where it intersects
    with useful practice. --Aahz
  • Doug Tolton at Aug 11, 2003 at 8:36 pm
    On Mon, 11 Aug 2003 14:17:38 -0500, Skip Montanaro wrote:

    Nope, no multi-line comment. The python-mode package which is available for
    Emacs and XEmacs supports commenting a block of text. You can also use
    triple-quoted strings:
    How do you comment the block of text with Emacs? That is what I'm
    using for my code editor.

    I was wondering if a triple-quoted string not assigned would work, but
    I hadn't got arround to trying it yet.

    Doug Tolton
  • David Bolen at Aug 11, 2003 at 9:54 pm

    Doug Tolton <dtolton at yahoo.com> writes:

    How do you comment the block of text with Emacs? That is what I'm
    using for my code editor.
    In Python mode, use C-c # to comment the selected region and C-u C-c #
    to uncomment a region. The commenting is done with "##" at the front
    of every line in the region, so it normally stands out from actual
    comments due to the #-doubling.

    -- David
  • Skip Montanaro at Aug 12, 2003 at 12:12 am
    Doug> How do you comment the block of text with Emacs? That is what I'm
    Doug> using for my code editor.

    "C-c #". Here's the doc:

    C-c # runs `py-comment-region'

    `py-comment-region' is an interactive compiled Lisp function
    -- loaded from "/Users/skip/emacs/python-mode.elc"
    (py-comment-region BEG END &optional ARG)

    Documentation:
    Like `comment-region' but uses double hash (`#') comment starter.

    Skip
  • John J. Lee at Aug 12, 2003 at 12:30 am
    Doug Tolton <dtolton at yahoo.com> writes:
    [...]
    How do you comment the block of text with Emacs? That is what I'm
    using for my code editor.
    C-c #

    I use C-x r k to uncomment (kill-rectangle), but I'm sure there must
    be an uncomment-region in there somewhere...

    I was wondering if a triple-quoted string not assigned would work, but
    I hadn't got arround to trying it yet.
    The only trouble with TCSs is that emacs gets confused more easily
    than with '## ' multiline-comments. And recent CVS python-modes have
    had broken docstring fill (still broken, actually, whitespace gets
    collapsed sometimes... must file a bug).


    John
  • Isaac To at Aug 12, 2003 at 10:42 am
    "John" == John J Lee <jjl at pobox.com> writes:
    John> Doug Tolton <dtolton at yahoo.com> writes: [...]
    How do you comment the block of text with Emacs? That is what I'm
    using for my code editor.
    John> C-c #

    John> I use C-x r k to uncomment (kill-rectangle), but I'm sure there
    John> must be an uncomment-region in there somewhere...

    Just do C-u C-c #

    Regards,
    Isaac.
  • John J. Lee at Aug 12, 2003 at 12:01 pm

    Isaac To <kkto at csis.hku.hk> writes:

    "John" == John J Lee <jjl at pobox.com> writes:
    [...]
    John> I use C-x r k to uncomment (kill-rectangle), but I'm sure there
    John> must be an uncomment-region in there somewhere...

    Just do C-u C-c #
    D'oh!


    John
  • Asun Friere at Aug 12, 2003 at 12:48 am
    Doug Tolton <dtolton at yahoo.com> wrote in message news:<4qofjvg3bh9smlnb1do4f0lhjga7bacnu3 at 4ax.com>...
    I've been using Python for quite some time now, and I'm a bit stumped.

    Does it really not have a multi-line comment? I think I must just be
    missing something simple and stupid.

    Thanks in advance.

    Doug Tolton
    #!/usr/bin/env python

    """This is a
    multiline comment.
    OK?"""
  • Christopher Blunck at Aug 13, 2003 at 5:07 am

    On Mon, 11 Aug 2003 14:17:38 -0500, Skip Montanaro wrote:
    Doug> I've been using Python for quite some time now, and I'm a bit
    Doug> stumped. Does it really not have a multi-line comment? I think I
    Doug> must just be missing something simple and stupid.

    Nope, no multi-line comment. The python-mode package which is available for
    Emacs and XEmacs supports commenting a block of text. You can also use
    triple-quoted strings:
    That always stumped me as well. Any idea what the justification for this
    was, Skip?


    -c
  • Sean 'Shaleh' Perry at Aug 13, 2003 at 6:06 am

    On Tuesday 12 August 2003 22:07, Christopher Blunck wrote:

    Nope, no multi-line comment. The python-mode package which is available
    for Emacs and XEmacs supports commenting a block of text. You can also
    use triple-quoted strings:
    That always stumped me as well. Any idea what the justification for this
    was, Skip?
    none of the other shell/script languages have one either. I rarely miss it.
  • Chad Netzer at Aug 13, 2003 at 6:21 am

    On Tue, 2003-08-12 at 23:06, Sean 'Shaleh' Perry wrote:
    On Tuesday 12 August 2003 22:07, Christopher Blunck wrote:

    Nope, no multi-line comment.
    That always stumped me as well. Any idea what the justification for this
    was, Skip?
    none of the other shell/script languages have one either. I rarely miss it.
    Multiline comments can be easily made with triplle quoted strings, or
    with Emacs (it folds long single line comments into multiple line
    comments). And for commenting out blocks of code, my good pal "if 0:"
    works great (along with block indent/dedent with a decent editor)

    --
    Chad Netzer
  • Doug Tolton at Aug 13, 2003 at 7:03 am

    On Tue, 12 Aug 2003 23:21:16 -0700, Chad Netzer wrote:
    (along with block indent/dedent with a decent editor)
    In emacs what are the key strocks for block indent and dedent?

    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.

    Doug Tolton
  • Chad Netzer at Aug 13, 2003 at 7:45 am

    On Wed, 2003-08-13 at 00:03, Doug Tolton wrote:

    (along with block indent/dedent with a decent editor)
    In emacs what are the key strocks for block indent and dedent?
    In python-mode:

    C-c >
    C-c <

    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.
    I don't even know 1%, but I know the 1% that counts. :)

    --
    Chad Netzer
  • Skip Montanaro at Aug 13, 2003 at 4:06 pm
    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.
    Chad> I don't even know 1%, but I know the 1% that counts. :)

    Your best friend when using various (X)?Emacs editing modes is

    C-h m

    You will sometimes stumble upon useful bits from the other 99%...

    Skip
  • Andrew McGregor at Aug 14, 2003 at 9:14 pm
    --On Wednesday, 13 August 2003 12:45 a.m. -0700 Chad Netzer
    wrote:
    On Wed, 2003-08-13 at 00:03, Doug Tolton wrote:

    (along with block indent/dedent with a decent editor)
    In emacs what are the key strocks for block indent and dedent?
    In python-mode:

    C-c >
    C-c <

    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.
    I don't even know 1%, but I know the 1% that counts. :)

    --
    Chad Netzer
    Try

    C-h ? ?

    which will give you the "help for help", which is how to learn the 5% or so
    that you need of the active keys in the modes you use (yes, emacs really
    does have that many keybindings! There are only 38 two-key sequences
    guaranteed available for user bindings...)

    Andrew

    ---------
    Andrew McGregor
    Director, Scientific Advisor
    IndraNet Technologies Ltd
    http://www.indranet-technologies.com/
  • Neil Padgen at Aug 13, 2003 at 10:51 am
    On Wednesday 13 August 2003 07:03, Doug Tolton wrote:
    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.
  • Francois Pinard at Aug 13, 2003 at 12:00 pm
    [Doug Tolton]
    Man, I wonder if I'll even learn 10% of the Emacs keystrokes.
    And then, you'll realise than pre-made keystrokes are only a small part
    of all available commands. And then, you'll realise that all available
    commands are only a small part of all available functions. And, of course,
    all of the above is only a small drop in the ocean of possibilities given
    by the capability of extending the editor with new functions. At times,
    I wonder if this should be seen as comforting or frightening. :-)
  • Skip Montanaro at Aug 13, 2003 at 4:08 pm
    Francois> At times, I wonder if this should be seen as comforting or
    Francois> frightening. :-)

    Adventurous...

    Skip
  • Tom Plunket at Aug 13, 2003 at 6:10 pm

    Chad Netzer wrote:

    In emacs what are the key strocks for block indent and dedent?
    In python-mode:

    C-c >
    C-c <
    Oh cool. I've been using C-x r o and C-x r k to open and kill
    rectangles. Your way seems much easier. ;) Thanks. ;)

    -tom!

    --
    There's really no reason to send a copy of your
    followup to my email address, so please don't.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 11, '03 at 6:48p
activeAug 14, '03 at 9:14p
posts22
users15
websitepython.org

People

Translate

site design / logo © 2022 Grokbase