how to comment lot of lines in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • diffuser78@gmail.com

    how to comment lot of lines in python

    Like in C we comment like
    /*
    Bunch of lines of code
    */

    Should we use docstring """ """

    Or there is something else too ??

    Every help is appreciated.

    Thanks

  • Felipe Almeida Lessa

    #2
    Re: how to comment lot of lines in python

    Em Qui, 2006-03-30 às 15:21 -0800, diffuser78@gmai l.com escreveu:[color=blue]
    > Like in C we comment like
    > /*
    > Bunch of lines of code
    > */
    >
    > Should we use docstring """ """
    >
    > Or there is something else too ??[/color]

    You should use a decent editor that could automatically
    comment/uncomment code upon your request.

    HTH,

    --
    Felipe.

    Comment

    • Tim Chase

      #3
      Re: how to comment lot of lines in python

      >>Or there is something else too ??[color=blue]
      >
      > You should use a decent editor that could automatically
      > comment/uncomment code upon your request.[/color]

      In Vim, you can map a key to do the following:

      :s/^/#

      to comment the highlighted lines, and

      :s/^#

      to uncomment them. To map them, you can use

      :vnoremap <f4> :s/^/#<cr>
      :vnoremap <f5> :s/#<cr>

      (those are literal "less-than, ["eff, [4 | 5]" | "see,
      are"], greater-than" characters)

      Then, pressing <f4> in visual mode will comment the selected
      lines, and pressing <f5> will uncomment any selected lines
      that are commented.

      The nice thing about vim's method of doing this, is that you
      can combine it with grepping. If you want to comment out
      every line containing a regexp, you can do

      :g/regexp/s/^/#

      Or, if you want to comment out from "regexp_1" to the
      following line containing "regexp_2", you can use

      :g/regexp_1/.,/regexp2/s/^/#

      All sorts of handy tricks.

      There are python plugins that I'm sure offer such abilities
      built-in. There are likely ways to do this in other editors
      too. I just happen to be a vim sorta guy.

      -tkc




      Comment

      • Laurent Rahuel

        #4
        Re: how to comment lot of lines in python

        diffuser78@gmai l.com wrote:
        [color=blue]
        > Like in C we comment like
        > /*
        > Bunch of lines of code
        > */
        >
        > Should we use docstring """ """
        >
        > Or there is something else too ??
        >
        > Every help is appreciated.
        >
        > Thanks[/color]
        Hi,

        Maybe this sounds simplier than regexp and so, just use the """ marker like
        this :

        """
        this
        would be
        commented
        during
        execution
        """


        Comment

        • Eric Deveaud

          #5
          Re: how to comment lot of lines in python

          diffuser78@gmai l.com wrote:[color=blue]
          > Like in C we comment like
          > /*
          > Bunch of lines of code
          > */
          >
          > Should we use docstring """ """[/color]

          I would say NO.
          docstring are displayed by pydoc, thus a pydoc on your code will display some
          inconsistent information ;-)
          [color=blue]
          > Or there is something else too ??[/color]

          some moderns editors allow you to comment/uncomment a selected Bunch
          of lines of code

          Eric
          --[color=blue]
          > afin de parfaire mon apprentissage de linux,je cherche sur lille et sa
          > périphérie une nana tout linux[/color]
          JPH in Guide du linuxien pervers : "Connaître le système"

          Comment

          • olsongt@verizon.net

            #6
            Re: how to comment lot of lines in python


            Eric Deveaud wrote:[color=blue]
            > diffuser78@gmai l.com wrote:[color=green]
            > > Like in C we comment like
            > > /*
            > > Bunch of lines of code
            > > */
            > >
            > > Should we use docstring """ """[/color]
            >
            > I would say NO.
            > docstring are displayed by pydoc, thus a pydoc on your code will display some
            > inconsistent information ;-)
            >[/color]

            docstrings are a bit of a magical construct. Not all strings in a
            function are docstrings.
            [color=blue][color=green][color=darkred]
            >>> def foo():[/color][/color][/color]
            .... "real docstring"
            .... """
            .... x=1
            .... """
            .... print x
            ....[color=blue][color=green][color=darkred]
            >>> help(foo)[/color][/color][/color]
            Help on function foo in module __main__:

            foo()
            real docstring
            [color=blue][color=green][color=darkred]
            >>>[/color][/color][/color]

            Comment

            • Eric Deveaud

              #7
              Re: how to comment lot of lines in python

              olsongt@verizon .net wrote:[color=blue]
              >
              > Eric Deveaud wrote:[color=green]
              > > diffuser78@gmai l.com wrote:[color=darkred]
              > > > Like in C we comment like
              > > > /*
              > > > Bunch of lines of code
              > > > */
              > > >
              > > > Should we use docstring """ """[/color]
              > >
              > > I would say NO. docstring are displayed by pydoc, thus a pydoc on your
              > > code will display some inconsistent information ;-)
              > >[/color]
              >
              > docstrings are a bit of a magical construct. Not all strings in a
              > function are docstrings.[/color]


              yep fogotten that triple quotted strings are considered as docstring
              only if they are the first lines of the module/fonction/class/method
              excluding the comments lines.

              my bad

              Eric

              --
              SYBEX ORIGINAL SOFTWARE
              NOUVEAU KIT LINUX REDHAT 5.2 POUR WIN 95/98
              -+- Sybex in Guide du linuxien pervers - "L'incompét ance en action" -+-

              Comment

              • Michael Hobbs

                #8
                Re: how to comment lot of lines in python

                Eric Deveaud wrote:[color=blue]
                > olsongt@verizon .net wrote:
                >[color=green]
                >> Eric Deveaud wrote:
                >>[color=darkred]
                >>> diffuser78@gmai l.com wrote:
                >>>
                >>>> Like in C we comment like
                >>>> /*
                >>>> Bunch of lines of code
                >>>> */
                >>>>
                >>>> Should we use docstring """ """
                >>>>
                >>> I would say NO. docstring are displayed by pydoc, thus a pydoc on your
                >>> code will display some inconsistent information ;-)
                >>>
                >>>[/color]
                >> docstrings are a bit of a magical construct. Not all strings in a
                >> function are docstrings.
                >>[/color]
                >
                >
                > yep fogotten that triple quotted strings are considered as docstring
                > only if they are the first lines of the module/fonction/class/method
                > excluding the comments lines.
                >[/color]
                The official rule is that if *any* string is the first line of a
                function/etc, it is considered a docstring. It's just standard
                convention to use the triple quotes for docstrings. As you mentioned,
                you can use triple quotes for any string; likewise, you can use standard
                quotes ( ' or " ) for docstrings as well.

                - Mike


                Comment

                • Dave Mandelin

                  #9
                  Re: how to comment lot of lines in python

                  I often use

                  if 0:
                  bunch of lines of code

                  That way, it's very easy to reenable the code, or to add an else, etc.
                  I can even put things like 'if 0 and USE_FOO_FEATURE ' to document what
                  is being commented out. It's much more flexible than commenting out.

                  --
                  Want to play tabletop RPGs over the internet?
                  Check out Koboldsoft RPZen: http://www.koboldsoft.com

                  Comment

                  • gene tani

                    #10
                    Re: how to comment lot of lines in python


                    diffuser78@gmai l.com wrote:[color=blue]
                    > Like in C we comment like
                    > /*
                    > Bunch of lines of code
                    > */
                    >[/color]

                    scite has a feature where you modify your delimiter in block comments,
                    i.e. what comes after "#"



                    Comment

                    • Sion Arrowsmith

                      #11
                      Re: how to comment lot of lines in python

                      Eric Deveaud <edeveaud@paste ur.fr> wrote:[color=blue]
                      >some moderns editors allow you to comment/uncomment a selected Bunch
                      >of lines of code[/color]

                      Out of curiousity, is there a modern editor which *doesn't* allow you
                      to comment/uncomment a selected bunch of lines of code?

                      --
                      \S -- siona@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
                      ___ | "Frankly I have no feelings towards penguins one way or the other"
                      \X/ | -- Arthur C. Clarke
                      her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

                      Comment

                      • Kent Johnson

                        #12
                        Re: how to comment lot of lines in python

                        Sion Arrowsmith wrote:[color=blue]
                        > Eric Deveaud <edeveaud@paste ur.fr> wrote:[color=green]
                        >> some moderns editors allow you to comment/uncomment a selected Bunch
                        >> of lines of code[/color]
                        >
                        > Out of curiousity, is there a modern editor which *doesn't* allow you
                        > to comment/uncomment a selected bunch of lines of code?
                        >[/color]
                        TextPad is my editor of choice but it doesn't have this feature.

                        Kent

                        Comment

                        • Rick Zantow

                          #13
                          Re: how to comment lot of lines in python

                          Kent Johnson <kent@kentsjohn son.com> wrote in news:44310867$1 _1
                          @newspeer2.tds. net:
                          [color=blue]
                          > Sion Arrowsmith wrote:[color=green]
                          >> Eric Deveaud <edeveaud@paste ur.fr> wrote:[color=darkred]
                          >>> some moderns editors allow you to comment/uncomment a selected Bunch
                          >>> of lines of code[/color]
                          >>
                          >> Out of curiousity, is there a modern editor which *doesn't* allow you
                          >> to comment/uncomment a selected bunch of lines of code?
                          >>[/color]
                          > TextPad is my editor of choice but it doesn't have this feature.
                          >[/color]

                          I use TextPad all the time, and while it is true that the feature is not
                          built in, it's misleading to say it doesn't have it. It is implemented by
                          means of a macro definition. I assign a key to a 'comment' macro (basically
                          replacing regex ^ with '# ' for the selected text) to do this. And of
                          course I have a reciprocal 'uncomment' macro as well.

                          --
                          rzed

                          Comment

                          • Frank Millman

                            #14
                            Re: how to comment lot of lines in python


                            Kent Johnson wrote:[color=blue]
                            > Sion Arrowsmith wrote:[color=green]
                            > > Eric Deveaud <edeveaud@paste ur.fr> wrote:[color=darkred]
                            > >> some moderns editors allow you to comment/uncomment a selected Bunch
                            > >> of lines of code[/color]
                            > >
                            > > Out of curiousity, is there a modern editor which *doesn't* allow you
                            > > to comment/uncomment a selected bunch of lines of code?
                            > >[/color]
                            > TextPad is my editor of choice but it doesn't have this feature.
                            >
                            > Kent[/color]

                            I also use TextPad - 4.7.3. I have never thought to comment a block of
                            code, but this thread prompted me to see if it is possible. As far as I
                            can see, you can do it like this -

                            Menu > Configure > Block Select Mode - Ctrl+Q,B

                            Select a block, one column wide, using mouse or keyboard.

                            Menu > Edit > Fill Block (brings up dialog box)
                            Fill character: #
                            Format: Left align
                            Fill mode: Replace
                            OK

                            Done.

                            To uncomment, as above but set Fill character to a space.

                            It feels a bit fiddly, but I reckon if you use it a few times it will
                            become quite smooth.

                            Frank Millman

                            Comment

                            • Kent Johnson

                              #15
                              Re: how to comment lot of lines in python

                              Rick Zantow wrote:[color=blue]
                              > Kent Johnson <kent@kentsjohn son.com> wrote in news:44310867$1 _1
                              > @newspeer2.tds. net:
                              >[color=green]
                              >> Sion Arrowsmith wrote:[color=darkred]
                              >>> Out of curiousity, is there a modern editor which *doesn't* allow you
                              >>> to comment/uncomment a selected bunch of lines of code?
                              >>>[/color]
                              >> TextPad is my editor of choice but it doesn't have this feature.
                              >>[/color]
                              >
                              > I use TextPad all the time, and while it is true that the feature is not
                              > built in, it's misleading to say it doesn't have it. It is implemented by
                              > means of a macro definition. I assign a key to a 'comment' macro (basically
                              > replacing regex ^ with '# ' for the selected text) to do this. And of
                              > course I have a reciprocal 'uncomment' macro as well.[/color]

                              Thank you! I don't suppose you have any tricks to make it work with
                              UTF-8 data outside the cp1252 character set, do you?

                              Kent

                              Comment

                              Working...