Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Problem with a Python script to count number of lines containing a word
-
I have the following text :
Paris Rome
London Berlin
London Rome
Paris Berlin Berlin
Rome London
Berlin Madrid
paris MadridI 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](link url)
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
-
When you iterate over a string, each iteration is one character of the string, not one line.
Use
for line in wftext.splitlines():
instead offor line in wftext:
, and it should work as expected. -
Thank you very much for your answer and, may I add, thank you very much for this indispensable app (together with Pythonista, of course…)