[prev in list] [next in list] [prev in thread] [next in thread]
List: libvir-list
Subject: Re: [libvirt] [PATCH] check-symfile: Use pythonesque string formatting instead of perl
From: Bjoern Walk <bwalk () linux ! ibm ! com>
Date: 2019-11-29 6:39:40
Message-ID: 20191129063940.GA4076 () huygens
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
Michal Privoznik <mprivozn@redhat.com> [2019-11-26, 09:48AM +0100]:
> That's exactly what I find horrible. Just consider the following example:
>
> print(f'a={f(x,n):d}, b={g(x,n):d}')
>
> IMO the following is more readable:
>
> print("a=%d, b=%d" % (f(x,n), g(x,n)))
First of all, the format specifiers (i.e, ":d") are completely optional
if you just care about the string representation of an object.
Secondly, I certainly hope that such code never passes code review
anywhere. Properly cleaning this up to
a = f(x,n)
b = g(x,n)
print(f"a={a}, b={b}")
is much more readable then the old-style
print("a=%d, b=%d" % (a, b))
or even the .format-style
print("a={}, b={}".format(a, b))
Also, format strings have the best performance for string interpolation
in python which is a non-bikeshed argument for them.
Bjoern
--
IBM Systems
Linux on Z & Virtualization Development
--------------------------------------------------
IBM Deutschland Research & Development GmbH
Schönaicher Str. 220, 71032 Böblingen
Phone: +49 7031 16 1819
--------------------------------------------------
Vorsitzende des Aufsichtsrats: Matthias Hartmann
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
["signature.asc" (application/pgp-signature)]
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic