omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Editorial
    2
    3
    2151
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tguillemin
      tguillemin last edited by

      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](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

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • tguillemin
          tguillemin last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors