473,830 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Mar 30 '06 #1
19 2213
Em Qui, 2006-03-30 Ã*s 15:21 -0800, di********@gmai l.com escreveu:
Like in C we comment like
/*
Bunch of lines of code
*/

Should we use docstring """ """

Or there is something else too ??


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

HTH,

--
Felipe.

Mar 30 '06 #2
>>Or there is something else too ??

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


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


Mar 31 '06 #3
di********@gmai l.com wrote:
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

Hi,

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

"""
this
would be
commented
during
execution
"""
Mar 31 '06 #4
di********@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 ;-)
Or there is something else too ??
some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code

Eric
-- afin de parfaire mon apprentissage de linux,je cherche sur lille et sa
périphérie une nana tout linux

JPH in Guide du linuxien pervers : "Connaître le système"
Mar 31 '06 #5

Eric Deveaud wrote:
di********@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 ;-)


docstrings are a bit of a magical construct. Not all strings in a
function are docstrings.
def foo(): .... "real docstring"
.... """
.... x=1
.... """
.... print x
.... help(foo) Help on function foo in module __main__:

foo()
real docstring


Mar 31 '06 #6
ol*****@verizon .net wrote:

Eric Deveaud wrote:
di********@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 ;-)


docstrings are a bit of a magical construct. Not all strings in a
function are docstrings.

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" -+-
Mar 31 '06 #7
Eric Deveaud wrote:
ol*****@verizon .net wrote:
Eric Deveaud wrote:
di********@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 ;-)

docstrings are a bit of a magical construct. Not all strings in a
function are docstrings.

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.

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
Mar 31 '06 #8
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

Mar 31 '06 #9

di********@gmai l.com wrote:
Like in C we comment like
/*
Bunch of lines of code
*/


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

http://scintilla.sourceforge.net/SciTEDoc.html

Mar 31 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3538
by: Riko Wichmann | last post by:
Dear all, is there a way in Python to comment out blocks of code without putting a # in front of each line? Somethings like C's /* block of code here is commented out */ Thanks,
16
2308
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the embedded comments I used the tokenize module. To my surprise the analysed output is different from the input (the last tuple element should exactly replicate the input line) The error comes out in correspondance of a triple string.
9
3049
by: Tim Anderson | last post by:
Does anyone else think VB should support the // prefix for comments? I keep using it by accident, because so many other languages use it (unlike the single quote, which is I believe unique to VB). If you think VB would be improved by this change, please vote on my suggestion here: http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackId=FDBK15038 Thanks!
16
1870
by: Christopher | last post by:
Hello all, I've got a question of comment logic. I'm trying to determine if a given line of C/C++/C#/Java is a comment or not. Can you please comment on my logic. I need to define some terms first: starts with = has only white space on the line untill it reaches ... first preceeding valid /* = looking back, the first /* from the current point in the file where the line does not have a // before the /*
3
2412
by: Martin P. Hellwig | last post by:
Hi all, I've been toying with python for about two years now. Not every day, just when I encounter something in my job (sysadmin) repetitively dull. The amazing thing is that like any other language (natural or not) learning it more gives you power to express your thoughts better and create something from nothing, for me this is something I can only compare to freedom. However since I'm learning more of python I've struggled with
29
2378
by: dbhbarton | last post by:
Had a thought that's grown on me. No idea if it's original or not- too inexperienced in programming- but I guess there's no harm floating it out there. Python wins big on readability, and there's no doubt that context- dependent text formatting in IDEs (keywords, strings, comments etc) is a massive help too, therefore benefitting development and maintenance. This idea is in a similar vein, especially for when scripts grow large.
3
1013
by: Ludwig Miniatur | last post by:
Hi, I ran into a funny thing when I played with the python parser, to build a python call graph for learning... When I have a (special) python program, that runs without any error it gives an error, when I try to parse it parser.suite. The error is, when my program has a comment on the last line after an indented block. Note that there no newline behind "# comment". With a newline everything is fine. For example:
39
2891
by: polas | last post by:
Afternoon all. I was just wondering about this point - I have (generally) used // for commenting a single line in C, but from looking at code other people have written it seems many use /* */ (which I only use if my comment will be over multiple lines) - does one way have any advantages over the other, or is the style exactly that, a question of style? Cheers, Nick
3
10859
by: Richard | last post by:
Again, new to DB2. Trying to do something I can do in Sybase ASE. In any Sybase SQL script I can use /* */ to comment out a block of code. In the DB2 9.0 SQL Reference Manual V1 it says: Comments: SQL comments are either bracketed (introduced by /* and end with */) or simple (introduced by two consecutive hyphens and end with
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.