Rjust & zfill not work


#1

I’m trying to add a extra zeros. But traditional methods do not work.

Maybe there is an alternative option?

import streams

s=streams.serial()
test = 5
while True:
    print( str(test).rjust(3,'0') )
    print( str(test).zfill(3) )
    sleep (1000)

#2

hi @trawen
These functions can be easily implemented.
For example :

name  = "string template"
def zfill(num_of_zeros,str):
    result = ('0'*num_of_zeros)+str
    return result

while True:
    print(zfill(8,name))   # print automatically knows where to print!
    sleep(1000)

>>00000000string template