linecache and comparison with input

Ross Hetherington ross at heth.eclipse.co.uk
Sat Jun 30 16:13:58 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Say I've got a file called 'testfile' that contains the following three
lines:

foo
bar
baz

And a script that goes like this:

#!/usr/bin/env python

import random
import sys
import linecache

rnd = random.randint(1,3)
line = linecache.getline('testfile', rnd)

print line

gss = raw_input('Enter line: ',)

if gss == line:
    print 'yes'
    sys.exit()
else:
    print 'no'


Even if the right word is entered, the script always prints `no'. Can
anyone explain why this happens?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFGhmUm0HlvQApfM3gRCl23AJ45cv7A0KVi2h8/cWmcCrg4X8HZOACfT6V8
IpXAzpD0jKnFFDEJEmOFvc4=
=UA5b
-----END PGP SIGNATURE-----



More information about the Python-list mailing list