Re: linecache and comparison with input
- From: Sebastian Wiesner <basti.wiesner@xxxxxxx>
- Date: Sat, 30 Jun 2007 16:27:50 +0200
[ Ross Hetherington <ross@xxxxxxxxxxxxxxxxxx> ]
#!/usr/bin/env pythonTry print repr(line) ...
import random
import sys
import linecache
rnd = random.randint(1,3)
line = linecache.getline('testfile', rnd)
print line
and print repr(gss) ;)
gss = raw_input('Enter line: ',)
if gss == line:
print 'yes'
sys.exit()
else:
print 'no'
Then you will see, that getline returns the line *including the newline
character*, while raw_input does not. Use line.strip('\n') to remove
trailing newline characters from the return value of getline.
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Attachment:
signature.asc
Description: This is a digitally signed message part.
- Follow-Ups:
- Re: linecache and comparison with input
- From: Ross Hetherington
- Re: linecache and comparison with input
- References:
- linecache and comparison with input
- From: Ross Hetherington
- linecache and comparison with input
- Prev by Date: linecache and comparison with input
- Next by Date: Re: linecache and comparison with input
- Previous by thread: linecache and comparison with input
- Next by thread: Re: linecache and comparison with input
- Index(es):