0

When i try to get a line using linecache in python.

loginpass = raw_input("> ")
if loginpass == linecache.getline('Password.txt', 1):

The line that it gets always returns with an extra line. So if line one is

"Test"

It returns

"Test
"

It worked earlier in the code but anything after that it adds that line after it.

1 Answers1

3

This is normal; reading lines from a file includes the line-ending newline character. Just strip it off:

linecache.getline('Password.txt', 1).rstrip('\n')

I'm more concerned that you're storing passwords in plain text, though....

kindall
  • 178,883
  • 35
  • 278
  • 309