有时为了整洁统一或者要求,需要在数字前补足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