[Tutor] Comparing two lines of print

Michael Janssen Janssen at rz.uni-frankfurt.de
Wed Jun 2 10:28:39 EDT 2004


On Wed, 2 Jun 2004, Bob Heasman wrote:

> Alan Gauld wrote:
> >>When I attempt to run this script I get a syntax error:-
> >>
> >>[root at penguin bob]# ./readfile.py
> >>   File "./readfile.py", line 14
> >>     if text_file.readline() == [PORT 6 (PTCPACTOR) - 19 - UA6ADV-0]
> >>                                      ^
> >>SyntaxError: invalid syntax
> >
> >
> > You are comparing a string (from raw_input()) with a list.
> > I assume you need quotes around the [PORT....-0] stuff?
> >
> > Alan G
> >
> >
> >
> Hello Alan,
>
> Yes I now see what is happening. When I had the quotes in it appeared
> to be ignoring two lines of code. Now I see that it IS comparing them
> and, due to the quotes, it says they are not the same.


it's very likly due to the trailing newline: lines captured with
raw_input have a newline (because you type ENTER).

Run this:

"""
inp = raw_input("Type Enter: ")
print repr(inp)
"""

the "repr" shows the newline in raw representation: "\n".


Michael



More information about the Tutor mailing list