That tripped me up too, empty strings are OK if you're using 'not s.isspace()'. Cheers -Terry
On November 12, 2016 11:10:50 AM CST, rengel <[email protected]> wrote: > > >> Instead of testing: >>> >> >> if not ''.join(lines).strip(): >> >> the new code now tests: >> >> if all([z.isspace() for z in lines]): >> >> >What do you want to accomplish? >The code 'z.isspace()' fails if a line is completely empty. Test: > >print(''.isspace()) # Fails >>> print(' '.isspace()) >>> print(' '.isspace()) >>> >>> >#!/usr/bin/python ># -*- coding: UTF-8 -*- > >import re > ># A test string, several blank lines >s1 = """ > > abc > > """ > >s2 = """ > > > > """ > ># Show the strings s1, s2 >print(s1, len(s1), s1.count('\n')) >print(s2, len(s2), s2.count('\n')) > ># Create lines from s1, s2 >lines1 = s1.split('\n') >lines2 = s2.split('\n') > ># Show the lines >print(lines1) >print(lines2) > ># EKR test, fails if a line is empty (= contains only '\n') >print(all([z.isspace() for z in lines1])) >print(all([z.isspace() for z in lines2])) > ># Using regular expression >print(re.match('^\s*$(?s)', s1)) >print(re.match('^\s*$(?s)', s2)) > > > >-- >You received this message because you are subscribed to the Google >Groups "leo-editor" group. >To unsubscribe from this group and stop receiving emails from it, send >an email to [email protected]. >To post to this group, send email to [email protected]. >Visit this group at https://groups.google.com/group/leo-editor. >For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
