Python 自动给数字前面补0

有时为了整洁统一或者要求,需要在数字前补足0到一定的位数,可使用zfill函数来操作,具体如下:

import configparser

conf = configparser.ConfigParser()
conf.read(r'E:\Projects\version.txt')
value_MainVersion = conf.get('Version', 'MainVersion')
value_SubVersion = conf.get('Version', 'SubVersion')
folder_name = "E:\Projects\test"
value_MainVersion = value_MainVersion.split('.')
for v in value_MainVersion:
    if len(v) == 1:
        v = v.zfill(2)
    folder_name += v
folder_name = folder_name + "_" + value_SubVersion
print(folder_name)
E:\Projects\test_022401_1

 

上一篇:Qt for Android修改应用程序的图标和名称


下一篇:Script to accelerate your accessibility test in Adobe Designer form - my IP