Reputation: 431
I have file that contains couple lines of text. I open the file this way in my code:
final = codecs.open("info", 'r', 'utf-8')
lines = final.readlines()
then I want to find exact lines:
if 'Edytuj'.join('\n') in lines:
#rest of code
I know the file contains 'Edytuj'
but that statement is always False
, am I making mistake somewhere?
Upvotes: 0
Views: 47
Reputation: 414139
with codecs.open("info", 'r', 'utf-8') as file:
for line in file:
if u'Edytuj\n' == line: # match full line
#rest of code
You could use if u'Edytuj' in line
if there may be other content in the line.
Upvotes: 0
Reputation: 309841
Have you looked at what 'Edytuj'.join('\n')
returns? (it returns '\n'
since you're joining an iterable of length 1). I'm guessing that's not what you meant to do.
What exactly do you want that test to do?
Maybe you meant:
if any('Edytuj' in line for line in lines):
pass #...
or possibly:
if 'Edytuj\n' in lines:
Upvotes: 3