On Wed, Sep 4, 2019 at 9:54 AM rengel <[email protected]> wrote:
Why not go for f-strings (Python 3.6+)...
>
> The code:
>
> def __repr__(self):
> # Better for g.printObj.
> val = str(self.val).replace('\n', ' ')
> return 'GS: %20s %7s = %s' % (
> g.shortFileName(self.path), self.kind, g.truncate(val, 50))
>
> would look as follows:
>
> def __repr__(self):
> # Better for g.printObj.
> val = (str(self.val).replace('\n', ' '))[0:50] # Save call to
> g.truncate
> return f'GS: {g.shortFileName(self.path):20} {self.kind:7} = {val}'
>
> Less typing, Smaller, faster, cleaner.
>
Actually, you will notice that the legacy way is slightly shorter :-) It's
a matter of preference, and I'm pretty stuck in my ways.
g.truncate(x, n) is not equivalent x[0:n]. Take a look.
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 view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1Vm0Y%2BaxNbNhxVqhUzPY73WWf74-GdWyM-ztEMJG3fWw%40mail.gmail.com.