3 Jul
2017
3 Jul
'17
11:59 a.m.
Stefan Schwarzer wrote:
On 2017-07-03 12:50, Hermann Riemann wrote:
computed_len=zahl=4 # Testzeile für Beispiel s="{:%d}"%computed_len print(s.format(zahl)) # Testzeile für Beispiel
Wie setze ich die Zeile mit s= nach format um?
Meinst du sowas:
"{{:{}d}}".format(5) '{:5d}'
Ich habe das jetzt auf die Schnelle aber auch nicht in der Doku gefunden, sondern hatte eine vage Erinnerung, dass ich da mal was gelesen hatte.
Falls es tatsächlich darum geht die Breite zur Laufzeit festzulegen, ist auch
computed_len = zahl = 4 print("{:{}}".format(zahl, computed_len)) 4
möglich.