Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Delete lines containing a specific word
Martin Marcher
1/6/2008 9:43:00 PM
On Sunday 06 January 2008 21:25 Francesco Pietra wrote:
>> yes lines starting with a "#" are comments in python but that shouldn't
>> be of concern for your input data. I don't quite get what you want
>> here...
>
> Leaving the lines commented out would permit to resume them or at least
> remeber what was suppressed. During trial and error set up of a
> calculation one never knows exactly the outcome
Ah I get it.
To clarify:
The character python uses as a comment has nothing to do with the character
your data file uses as a comment.
So you could of course use the "#" sign (which makes sense)
You could also use "//" (C-Style) or whatever you like
class CommentHelper(object):
"""Provides the necessary
methods to comment or uncomment a line of text.
"""
# Yes I know this docstring is badly formatted but
# I thought it's nicer to keep the indentation.
def __init__(self, commentStr=None):
if commentStr:
self.commentStr = commentStr
else:
self.commentStr = "MY_SUPER_COMMENT_STRING"
def commentLine(line):
"""Comments a line with the
initialized comment string.
"""
return self.commentStr + " " + line
def uncommentLine(line):
"""Uncomments a line iff it is
preceded by the comment string.
"""
if line.startsWith(self.commentStr):
return line[len(self.commentStr)].lstrip()
raise Exception("Can't uncomment Line with no comment")
You want to read up about:
* (new style) classes
* parameters with default values
* docstrings
* Exceptions
That code is untested and may contain errors. I'll let the debugging be your
task :)
hope it points you to the right topics to read up about:
http://docs.p...
http://docs.p...
tut/tut.html
http://www.diveintop...
martin
--
http://noneisyours.ma...
http://feeds.feedburner.com/N...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Delete lines containing a specific word
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password