On Friday, November 25, 2016 at 7:59:56 AM UTC-6, rengel wrote:
> Why use two functions, when one suffices?
>
> def strip_lws(s):
> return '\n'.join([z.lstrip() for z in s.splitlines(False)])
>
Beautiful. I'm going to make this change today.
The Importer class uses i.lstrip_line() in one other place:
def clean_blank_lines(self, lines):
'''Remove all blanks and tabs in all blank lines.'''
return [self.lstrip_line(z) if z.isspace() else z for z in lines]
But this could also be rewritten, asserting that every line ends in '\n':
def clean_blank_lines(self, lines):
'''Remove all blanks and tabs in all blank lines.'''
assert all([z.endswith('\n') for z in lines]), g.callers()
return ['\n' if z.isspace() else z for z in lines]
Leo uses g.splitLines(s) rather than s.splitlines(True). Three characters
shorter ;-)
Somehow I had it in my head they are different...
def splitLines(s):
if s:
return s.splitlines(True)
else:
return []
But they are identical, unless s isn't a string, in which case g.splitLines
shouldn't be called!
Provided all tests pass, it's probably safe to define g.splitLines as:
def splitLines(s):
assert g.isString(s), (repr(s), g.callers())
return s.splitLines()
Thanks, Reinhard, for educating me about s.isspace() and s.splitlines().
Edward
--
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.