f='demo.py'
with open(f,'r')as fp:
lines=fp.reaadlines()
maxlines=len(max(lines,key=len))
lines=[line.rstrip().ljust(max)+'#'+str(index)+'\n' for index,line in enunmerate(lines)]
with open(filename[:-3]+'_new.py','w')as fp:
fp.writelines(lines)
程序行号和with函数
最新推荐文章于 2024-09-04 10:31:20 发布