In short, we are getting to matters of style. Imo, this:
>
>> return [self.lstrip_line(z) for z in lines]
>>
>> is slightly preferable to:
>>
>> return ['\n' if z.isspace() else z.lstrip() for z in lines]
>>
>>
> Furthermore, i.clean_blank_lines() uses i.lstrip_line():
>
> 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]
>
> Yes, we could replace the call to self.lstrip_line, but that would create
> nested ternary operators, which I avoid on stylistic grounds.
>
>
I still don't understand why you are struggling with the newline characters
at all. Do you need them for some internal processing? Otherwise the
command
lines = s.splitlines(False)
(s being the input string) gets rid of all trailing newline characters; and
you can use lstrip() to do all the cleanup of the strings. You no longer
need isspace or any case distictions to cleanup the lines:
def clean_blank_lines(self, lines):
'''Remove all blanks and tabs in all blank lines.'''
return [z.lstrip() for z in lines]
Or more concisely: You can skip the creation of the lines and do it all in
one sweep:
def clean_blank_lines(self, s):
'''Remove all blanks and tabs in all blank lines.'''
assert s, g.callers()
return [z.lstrip() for z in s.splitlines(False)]
Reinhard
--
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.