Jump to content

Recommended Posts

Well I got a solution. Don't know if it is most elegant and efficient.

#@ Create cad point name
number_ = (name).split (".")[0][1:]
len_number = len(number_)
i = 1
while i < ( 5 -len_number):
	number_ = "0" + number_
	i = i +1
user_bmwimport_ipe_type+"_"+name[0]+"_"+number_

 

Link to comment
https://qualityforum.zeiss.com/topic/135-padding-a-string-woth-000/#findComment-384
Share on other sites

  • 2 months later...

in Python 2 (and Python 3) you can do:

print ("%04d" % 1) #4 is the number of digits you want
#print : 0001

For Python 3.+, the same behavior can also be achieved with format:

print("{:04d}".format(1))
#print : 0001

For Python 3.6+ the same behavior can be achieved with f-strings:

print(f"{1:04d}")
#print : 0001

the 3 methods works in gom

Link to comment
https://qualityforum.zeiss.com/topic/135-padding-a-string-woth-000/#findComment-628
Share on other sites

×
×
  • Create New...