[Tutor] Equality Check.

Joel Goldstick joel.goldstick at gmail.com
Mon Mar 3 00:32:31 CET 2014


On Mar 2, 2014 6:30 PM, "Mark Lawrence" <breamoreboy at yahoo.co.uk> wrote:
>
> 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,
>>readlines result must be put somewhere
>> 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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140302/b95e7b47/attachment.html>


More information about the Tutor mailing list