[Tutor] Equality Check.

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Mar 3 00:29:16 CET 2014


On 02/03/2014 21:10, Tyler Simko wrote:
> Hi all!
>
> I'm embarrassingly new at Python, so please forgive my probably simple mistakes.
>
> So I called readlines() on a file, and I'm wondering how I can check the equality of a specific line with a raw_input set variable as a condition. For example,
>
> file = open('filename.txt,' 'r')
> file.readlines()
> variable_name = raw_input()
> if file[2] == variable_name:
>       #whatever
>
> This approach hasn't worked so far, does anyone have any tips? Thanks so much!!
>
> -Tyler

You haven't stripped the newline before doing the comparison.  You also 
don't have to read the whole file just to compare a specific line.  I'll 
leave you to find out how :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com




More information about the Tutor mailing list