Re: commenting out blocks of code

Discussion in 'Python' started by Paul McNett, Feb 18, 2006.

  1. Paul McNett

    Paul McNett Guest

    john peter wrote:
    > in java, i can prevent a block of code from executing
    > by bracketing the block with comment indicators, as shown
    > below:
    > /*
    > statement1 will not execute;
    > statement2 will not execute;
    > */
    > statement3 will execute
    >
    > is there a similar mechanism in python, other than prefixing
    > the '#' character to the start of each statement i do not
    > want to execute (which gets old very quickly if one needs to
    > comment and uncomment several statements a couple of
    > times while "playing around with code" say during initial design)?


    IMO this is a missing feature in Python. However, if the block of code
    you are wanting to comment out doesn't happen to contain any
    triple-quotes, you can surround the code with those. For example:

    def myFunc(arg):
    return arg + 2

    """
    def myFunc(arg):
    return arg + 1
    """

    >>> print myFunc(2)

    4


    --
    Paul
    Paul McNett, Feb 18, 2006
    #1
    1. Advertising

  2. In article <>,
    Paul McNett <> wrote:
    .
    .
    .
    >IMO this is a missing feature in Python. However, if the block of code
    >you are wanting to comment out doesn't happen to contain any
    >triple-quotes, you can surround the code with those. For example:
    >
    >def myFunc(arg):
    > return arg + 2
    >
    >"""
    >def myFunc(arg):
    > return arg + 1
    >"""
    >
    > >>> print myFunc(2)

    >4

    .
    .
    .
    .... and note that, even if the block *does* contain triple-quotes
    of one flavor, you can use the other:

    '''This is syntactic data: """.

    '''
    Cameron Laird, Feb 18, 2006
    #2
    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. =?Utf-8?B?U2FuZHk=?=

    Commenting out VB code

    =?Utf-8?B?U2FuZHk=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    51,774
    =?Utf-8?B?Sm9uWg==?=
    Feb 3, 2005
  2. patrick

    java commenting out of code

    patrick, Jan 11, 2006, in forum: Java
    Replies:
    4
    Views:
    5,163
    Malte Christensen
    Jan 11, 2006
  3. Peter Hansen

    Re: commenting out blocks of code

    Peter Hansen, Feb 18, 2006, in forum: Python
    Replies:
    8
    Views:
    1,281
    Neil Hodgson
    Feb 20, 2006
  4. Jean-Paul Calderone

    Re: commenting out blocks of code

    Jean-Paul Calderone, Feb 18, 2006, in forum: Python
    Replies:
    0
    Views:
    464
    Jean-Paul Calderone
    Feb 18, 2006
  5. matt
    Replies:
    1
    Views:
    233
    George Ogata
    Aug 6, 2004
Loading...

Share This Page