Help, re SMTP posting / RFC822
Benjamin Schollnick
junkster at nospam.rochester.rr.com
Fri Sep 17 04:33:20 EDT 1999
On Fri, 17 Sep 1999 07:05:21, "Phil Mayes" <nospam at bitbucket.com>
wrote:
Uh, works for me:
> >>> s = 'abc'
> >>> s = s + '<'
> >>> s
> 'abc<'
>
> I suspect from the inconsistent indentation of your post that you're
> mixing tabs and spaces. I believe this is a Mandatory Python
> Learning Experience.
I've been using a combination of DOS edit & Windows Notepad, I've even
retyped
that code to ensure there is no tabs in their....So their shouldn't be
any in there.
I'll have to reload python on that box, to try to ensure that it's not
a beta version of 1.52.
> By the way, you can improve performance and legibility with:
>
> tmp = string.splitfields(persons_to_mailto, ',')
> self.to_text = 'To: '
> for s in tmp:
> self.to_text = self.to_text + '<%s>\n' % s
That's the one method I didn't try, substitution. I just (a few days
ago) read about it,
and forgot entirely about it.
> >2) I'm confused about using variables from a OBJECT, inside a routine
> >of said object. I was able to write the entire POP3.PY code without
> >using SELF.<VAR NAME> and ran it. It seemed that certain
> >routines needed SELF, and others would seem to work fine w/o the
> >self. Have I used self correctly, or horribly misused it?
>
> Looked OK to me; not sure what you mean here about the pop3 code.
> Want to amplify?
Okay, for example:
Path:
typhoon.nyroc.rr.com!cyclone.nyroc.rr.com!news.nyroc.rr.com!typhoon.ny
roc.rr.com.POSTED!not-for-mail
From: junkster at nospam.rochester.rr.com (Benjamin Schollnick)
Message-ID: <rNHvjEdhm5Pp-pn2-7N3prdWbd0Wt at d185d1865.rochester.rr.com>
Newsgroups: comp.lang.python
Subject: Help, re SMTP posting / RFC822
X-Newsreader: ProNews/2 Version 1.50 Beta 1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 8bit
Lines: 132
Date: Fri, 17 Sep 1999 00:24:32 GMT
NNTP-Posting-Host: 24.93.24.101
X-Complaints-To: abuse at rochester.rr.com
X-Trace: typhoon.nyroc.rr.com 937527872 24.93.24.101 (Thu, 16 Sep 1999
20:24:32 EDT)
NNTP-Posting-Date: Thu, 16 Sep 1999 20:24:32 EDT
Organization: Time Warner Road Runner - Rochester NY
Xref: cyclone.nyroc.rr.com comp.lang.python:1058922
Folks,
It looks like I need some more advance Python shoulders to cry on and
ask for
help, again......
I'm working on some code for a CGI package at work. Which, by the
way, I've already been given permission to release here once I'm done.
I'd like to get some feedback to help improve my python coding.
But, this is just a small part of it, yet, I've got two doosy of a
question(s).
1) def mail_to (self, persons_to_mailto):
tmp = ''
tmp = string.splitfields(persons_to_mailto, ',')
self.to_text = 'To: '
for count in range(len(tmp)):
# self.to_text = self.to_text + '<'
self.to_text = self.to_text + tmp[count]
# self.to_text = self.to_text + '\x3E'
self.to_text = self.to_text + '\n'
See the two commented lines? I can't get them to work in *ANY* form.
If I have the < or > character
in 'em, python just seems to goof up and no value gets placed into
TO_TEXT.
I seem to remember the Greater & Less signs having a special
representation code (i.e. \n) in python but can't back it up with
documentation. (I looked but couldn't find it).
I've tried hex representations, CHR(60) / CHR(62), and a few other
tries to work around this, but haven't succeeded.
2) I'm confused about using variables from a OBJECT, inside a routine
of said object. I was able to
write the entire POP3.PY code without using SELF.<VAR NAME> and ran
it. It seemed that certain
routines needed SELF, and others would seem to work fine w/o the
self. Have I used self correctly,
or horribly misused it? (See full code below)
3) Anyone got any suggestions on making this code "more intuitive" or
better python code? It's simplistic I know, but I'm still getting
the hang of python and trying to supress my Borland Pascal OOP
experience(s).
Thanks in advance,
- Benjamin
----------- POP3.PY (full) -------
#
#
#
import string
class sendpop3:
def __init__(self):
self.to_text = ''
self.from_text = ''
self.subject_text = ''
self.header_text = ''
self.body_text = ''
self.body_sep = '\n\n'
def mail_to (self, persons_to_mailto):
tmp = ''
tmp = string.splitfields(persons_to_mailto, ',')
self.to_text = 'To: '
for count in range(len(tmp)):
# self.to_text = self.to_text + '<'
self.to_text = self.to_text + tmp[count]
# self.to_text = self.to_text + '\x3E'
self.to_text = self.to_text + '\n'
def mail_from (self, persons_who_are_mailing):
# from_text = 'From:
'+string.splitfields(persons_who_are_mailing, ',')+ '\n'
tmp = ''
tmp = string.splitfields(persons_who_are_mailing, ',')
self.from_text = 'From: '
for count in range(len(tmp)):
self.from_text = self.from_text + tmp[count] + '\n'
def return_mail_from (self):
return from_text
def return_mail_to (self):
return self.to_text
def mail_subject (self, subject):
self.subject_text = 'Subject: ' + subject+ '\n'
def start_body_text (self):
self.body_text = ''
def append_body_line (self, bodytext_to_add):
def return_message (self):
tmp_message = ''
tmp_message = to_text + ' ' + from_text + ' '
+body_sep + to_text + ' ' + from_text + subject_text + body_text
return tmp_message
On this routine, I was getting name lookup errors, until I changed
the references to include "self.",
which makes some degree of sense. But then, I was getting Attribute
Errors, until I changed all the
other calls in the module to be self's.
It makes sense, but I was suprised that I would manually (via self)
have to tell python that the data
is from the object's local namespace, instead of it automatically
recognizing that. (Ala Borland Pascal)
- Benjamin
More information about the Python-list
mailing list