[Tutor] breakfast of champions [pydoc/overcommenting?/functions]
Wed, 12 Dec 2001 00:32:46 -0800 (PST)
On Wed, 12 Dec 2001, Kirk Bailey wrote:
> cold pizzia.
Don't stay up too late. *grin* I'm jealous; I have to wake up earlier
tomorrow. Eat some veggies too.
> digest them rfc822 headers still. Coming along. Found the definition for
> find int he on line documenting. Makes sense really, although I would
> have thought there would be a search method alredy in the language, but
> hey, it works.
There is something of a search method in the 'pydoc' module. After
importing the pydoc module, try typing:
from an interpreter, and you should see a bunch of help.
In fact, strings already have a find() function:
Help on function find in string:
find(s, sub [,start [,end]]) -> in
Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
so you can just use it: you don't have to define it again.
> Also must add a loop to read the subscriber file and STRIP OFF the \n
> on the end of each line, and append it to the list before searching
> it, as it kills the search. Pity I cannot think of way to do that on
> the fly while loading with readlines. Any suggestions?
You'll like this one: you can use a string.replace() to remove '\n's from
a string that you're reading. For example:
>>> s = 'this is a string\n\nwith newlines\n'
>>> import string
>>> string.replace(s, '\n', '')
'this is a stringwith newlines'
It's my personal opinion that your code has way too many comments.
*grin* I think that things like:
> localhost = 'howlermonkey.net' # make sure you set this to the domain
# YOU use!!!
are fine, but that:
> listname = sys.argv # we read a command line arguement to
# determine the list name
# Arguement 0 is the name of
# the script run, 1 is the
# first arguement.
# after that name in the command line,
# so if this were program FOO,
# that line would be "|/path/FOO listname"
# and the arguement here would be 'listname'!
and examples like that are overkill. These are just an opinion though, so
don't take me too seriously on this.
You have a large portion of code that begins here:
> subject = '[' + listname + ']' + subject # then acept the submission.
> Reply_to = listname + "@" + localhost # this sets the reply-to field.
[... code cut]
that may be a prime candidate for a function --- it could be something
that constructsMessage() or something to that effect.