[Tutor] Matching zipcode in address file

Alan Gauld alan.gauld at btinternet.com
Tue Apr 6 09:45:26 CEST 2010


"TGW" <galaxywatcher at gmail.com> wrote 
>I got it. I was comparing '345' to '345\n'
> 
> Adding the '\n' to the slice did indeed do the trick.

Yes, the problem is that the data in the file always has a \n at the end.
So you either have to rstrip() that off when you read it from the file 
or add a \n to your source data when comparing it with file data.

Personally I usually use strip() so that I'm working with 'clean' data
both for source and reference.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list