if report == True:
print ("\tActive parts:\t%s")%(len(pact)) # TOTAL P Part and Active
print ("\tDiscontinued parts:\t%s")%(len(pdisc)) # TOTAL P Part and Discontinued
print ("\tSlow-moving parts:\t%s")%(len(pslow)) # TOTAL P Part and Slow-moving
print ("\tObsolete parts:\t%s")%(len(pobs)) # P TOTAL Part and Obsolete
我怎样才能最好地简化上述内容?我还有大约80条其他的打印语句,比如那些使代码很难使用的语句?你知道吗
把模板写成“常量”,然后
print( template % dictionary_of_values)
澄清:
重新考虑代码的因素,以便将各个变量存储在字典中,例如
甚至作为类的属性
然后创建一个单独的字符串列表来描述每个属性,例如:
然后你可以这样打印它们:
您可以创建一个包含所有标签和值的元组列表,并执行如下循环:
相关问题 更多 >
编程相关推荐