470,591 Members | 2,283 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

POP3 Mail Download

Having some troubles downloading messages with POP3...

I can connect to the server just fine and list messages without any
problem with the following code:

------------------------
from poplib import *

server = POP3("mail.bluebottle.com")
print server.getwelcome()
print server.user("ne*******@bluebottle.com")
print server.pass_("xxxxxxxx")

messagesInfo = server.list()[1]
numMessages = len(messagesInfo)

print numMessages
------------------------

However, if I try to actually download the messages themselves, my
python editor highlights 'msgSize' and says "invalid syntax" when I run
the following subsequent lines of code:
------------------------
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)
------------------------

anyone know what's wrong? thanks.
Mar 18 '06 #1
8 1538
Dennis Lee Bieber wrote:
On Sat, 18 Mar 2006 16:44:44 -0500, Kevin F <ne*******@gmail.com>
declaimed the following in comp.lang.python:

However, if I try to actually download the messages themselves, my
python editor highlights 'msgSize' and says "invalid syntax" when I run
the following subsequent lines of code:
------------------------
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)


Look very closely at your indentation


I fixed the indentation to:

emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)
and it still doesn't work, what's wrong?
Mar 18 '06 #2
Dennis Lee Bieber wrote:
On Sat, 18 Mar 2006 17:24:05 -0500, Kevin F <ne*******@gmail.com>
declaimed the following in comp.lang.python:
I fixed the indentation to:

emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]


Now look at your parentheses...
and it still doesn't work, what's wrong?

msgNum = int(split(msg, " ")[0]

HINT: 0 1 2 1 ?

i have no idea what you are hinting at, can you please just tell me what
i need to change?
Mar 18 '06 #3
"Kevin F" <ne*******@gmail.com> wrote in message
news:dv***********@netnews.upenn.edu...
Dennis Lee Bieber wrote:
On Sat, 18 Mar 2006 16:44:44 -0500, Kevin F <ne*******@gmail.com>
declaimed the following in comp.lang.python:

However, if I try to actually download the messages themselves, my
python editor highlights 'msgSize' and says "invalid syntax" when I run
the following subsequent lines of code:
------------------------
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)


Look very closely at your indentation


I fixed the indentation to:

emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)
and it still doesn't work, what's wrong?


See comments.
-- Paul
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0] # line is missing closing paren
msgSize = int(split(msg, " ")[1] # line is missing closing paren,
too
if(msgSize < 20000): # this line should not be
further indented
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)

Mar 19 '06 #4
Paul McGuire wrote:
"Kevin F" <ne*******@gmail.com> wrote in message
news:dv***********@netnews.upenn.edu...
Dennis Lee Bieber wrote:
On Sat, 18 Mar 2006 16:44:44 -0500, Kevin F <ne*******@gmail.com>
declaimed the following in comp.lang.python:
However, if I try to actually download the messages themselves, my
python editor highlights 'msgSize' and says "invalid syntax" when I run
the following subsequent lines of code:
------------------------
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)
Look very closely at your indentation

I fixed the indentation to:

emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]
if(msgSize < 20000):
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)
and it still doesn't work, what's wrong?


See comments.
-- Paul
emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0] # line is missing closing paren
msgSize = int(split(msg, " ")[1] # line is missing closing paren,
too
if(msgSize < 20000): # this line should not be
further indented
messages = server.retr(msgNum)[1]
messages = join(message, "\n")
emails.append(message)

thanks, that helped fix the syntax error, however, now when i run it, it
gives me an error for 'split', saying "name 'split' is not defined"

i'm new to python so bear with me but how do i fix this?
Mar 19 '06 #5
On Sat, 18 Mar 2006 18:34:56 -0500, Kevin F wrote:
Dennis Lee Bieber wrote:
On Sat, 18 Mar 2006 17:24:05 -0500, Kevin F <ne*******@gmail.com>
declaimed the following in comp.lang.python:
I fixed the indentation to:

emails = []
for msg in messagesInfo:
msgNum = int(split(msg, " ")[0]
msgSize = int(split(msg, " ")[1]


Now look at your parentheses...
and it still doesn't work, what's wrong?

msgNum = int(split(msg, " ")[0]

HINT: 0 1 2 1 ?

i have no idea what you are hinting at, can you please just tell me what i
need to change?


I know how you feel; it's brutal trying to get elementary information from
this group.

I think what he is hinting at is that you are missing a right parentheses.

msgNum = int(split(msg, " ")[0]

should be:

msgNum = int(split(msg, " "))[0]
msgSize = int(split(msg, " ")[1]

should be:

msgSize = int(split(msg, " "))[1]
Now if only somebody would tell me, with elementary examples, how you
write to the thing called 'stdout' and how you read from 'stdin'.

Mar 19 '06 #6
Kevin F <ne*******@gmail.com> wrote:
...
msgSize = int(split(msg, " ")[1] # line is missing closing paren,
... thanks, that helped fix the syntax error, however, now when i run it, it
gives me an error for 'split', saying "name 'split' is not defined"

i'm new to python so bear with me but how do i fix this?


you change the above-quoted assignment into:

msgSize = int(msg.split()[1])

and similarly for other occurrences of split, which is a string method
(and needs to be called as such) and not a builtin function.
Alex
Mar 19 '06 #7
Bob Piton wrote:
On Sat, 18 Mar 2006 18:34:56 -0500, Kevin F wrote:
i have no idea what you are hinting at, can you please just tell me what i
need to change?

I know how you feel; it's brutal trying to get elementary information from
this group.


You could try the python-tutor list, it tends to give more focused
answers to newbie questions than this group, which is pretty
newbie-friendly but does have a tendency to veer widely from the
original question.
Now if only somebody would tell me, with elementary examples, how you
write to the thing called 'stdout' and how you read from 'stdin'.


raw_input() prompts to stdout and reads from stdin. print outputs to stdout:

In [53]: print raw_input('What is your name? ')
What is your name? Kent
Kent

or import sys and use sys.stdin and sys.stdout.

Kent
Mar 19 '06 #8
Bob Piton wrote:
I think what he is hinting at is that you are missing a right parentheses.

msgNum = int(split(msg, " ")[0]
should be:
msgNum = int(split(msg, " "))[0] Or more likely:
msgNum = int(split(msg, " ")[0])
msgSize = int(split(msg, " ")[1]
should be:
msgSize = int(split(msg, " "))[1] Similarly:
msgSize = int(split(msg, " ")[0])

More readably:
msgNum, msgSize = [int(text) for text in split(msg, " ")[:2]]
Now if only somebody would tell me, with elementary examples, how you
write to the thing called 'stdout' and how you read from 'stdin'.

import sys
print 'parrot' # writes to sys.stdout
print >>None, 'limburger' # Also writes to sys.stdout
print >>sys.stdout, 'roquefort' # Also writes to sys.stdout
sys.stdout.write('Shropshire -- the cheese of the gods\n) # Also

oneline = raw_input('prompt: ') # reads from sys.stdin
for line in sys.stdin: # reads line from sys.stdin
print 'The current line is: %r' % line
if not line.strip():
break
chunk = sys.stdin.read(23) # reads a series of bytes from sys.stdin

Warning: idle does not implement line iteration as in the for loop.
Also the read in both line iteration and .read(N) may well read the
input in "block mode", so you may have to type-ahead or end with an
end-of-file (^D for Unix, ^Z for Windows) before it starts processing
the lines.

--Scott David Daniels
sc***********@acm.org
Mar 19 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by WebRod | last post: by
6 posts views Thread by Robin Becker | last post: by
1 post views Thread by Ajeet YS | last post: by
2 posts views Thread by Mike Brearley | last post: by
2 posts views Thread by Shimon Sim | last post: by
4 posts views Thread by Pavils Jurjans | last post: by
1 post views Thread by rodny.romero | last post: by
reply views Thread by =?Utf-8?B?Q2hhcmxlcw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.