POP3 Mail Download

Scott David Daniels scott.daniels at acm.org
Sat Mar 18 22:40:28 EST 2006


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
scott.daniels at acm.org



More information about the Python-list mailing list