[libvirt] [PATCH] check-symfile: Use pythonesque string formatting instead of perl

Bjoern Walk bwalk at linux.ibm.com
Fri Nov 29 06:39:40 UTC 2019


Michal Privoznik <mprivozn at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 902 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191129/b376c461/attachment-0001.sig>


More information about the libvir-list mailing list