Forum Archive

Problem with a Python script to count number of lines containing a word

tguillemin

I have the following text :

Paris Rome
London Berlin
London Rome
Paris Berlin Berlin
Rome London
Berlin Madrid
paris Madrid

I wish to count the number of lines containing London (3 lines)

I run the following workflow

http://www.editorial-workflows.com/workflow/5858062694875136/Sy1_sF8-Vbs

which gives me the answer "The word London occurs in 0 lines" (but the highlighting on the contrary is correct)

The explanation is most certainly evident, but I cannot find it…

Where did I go wrong ?

Thanks in advance

omz

When you iterate over a string, each iteration is one character of the string, not one line.

Use for line in wftext.splitlines(): instead of for line in wftext:, and it should work as expected.

tguillemin

Thank you very much for your answer and, may I add, thank you very much for this indispensable app (together with Pythonista, of course…)