[Tutor] another intresting script

Jeff Shannon jeff@ccvcorp.com
Tue, 11 Dec 2001 09:44:15 -0800

Kirk Bailey wrote:

>     def prompt(prompt):
>         return raw_input(prompt)string.strip()

Here, you've got an extra 'string' that is non-functional.  Looks like you corrected
this in your second example, though.  You're also re-using the same name for two
different things (the function, and its parameter), which is probably not a good idea.
It should be

def prompt(promptstring):
    return raw_input(promptstring).strip()

Other than that, it's hard to guess what exactly is happening, since you don't give
specific error messages, or say which variable is not getting the newline that you think
it should (and we don't know *where* you expect that newline to be added, either).  You
might try adding a "print repr(msg)" at the same point that you're printing the message
length, and see if it looks like you expect there.

Oh, wait, I see what's probably happening...

    while 1:
            line = raw_input()
        except EOFError:
        if not line:
        msg = msg + line

You're not getting newlines at the end of each line, here, right?  They are not
automatically added by raw_input(), so you'd need to add them yourself, something like

    msg = msg + line + '\n'

Hope that helps!

Jeff Shannon
Credit International