[Tutor] further ignorant babbling
Sun, 2 Dec 2001 13:58:14 -0800 (PST)
On Sat, 1 Dec 2001, Kirk Bailey wrote:
> import strings
This might be a typo: you probably mean "import string" instead.
> import mail
> # define path information and domain name in the lines below
> domainname = 'howlermonkey.net'
> pathtosubscribers = '/www/www.howlermonkey.net/cgi-bin/lists'
> # receive the incoming letter from <stdin>
> # parse the letter into a dictionary
Python is "dynamically typed", so you don't need to tell Python that
"letter" will be a dictionary. If 'Mail.parse(incoming)' returns a
letter = Mail.parse(incoming)
should be enough. Be careful! 'Mail' is uppercased here, but your import
uses a lowercased 'mail'. I'm not sure which one is right, but you'll
need to check this.
> # clip off preceeding and trailing whitespace chars if any
You probably mean:
to = string.strip(to)
There's some documentation on the 'string' module here:
> # this next gives us the part after 'To:' and before '@'
> to = string.string( letter, string.pos("@",3, 'to:'))
Hmmm... You might want to write this as a separate function, because it
does seem like a useful thing to have. Here's an example function that
knows how to strip the domain out of an email address:
end = string.find(email, '@')
Once we have a function like this, we can use it as if it were part of
Functions are often fun to write: by writing functions, we can expand the
number of "verbs" we can use in our programs.