求助
问题如下:假设文件listin.txt内容为:
Digital Intermediate by : EFILM
Supervising Digital Colorist : STEVEN J. SCOTT
Second Colorist :ANDREW FRANCIS
Digital Intermediate Producer:LOAN PHAN
DigitalIntermediate Editor:DEVON MILLER
表示冒号固定位置的整数为:40
代码如下:
a=[]
y=open('源.txt')
for eachline in y:
a.append(eachline.strip())
y.close()
for i in range(len(a)):
b=a.split(':')
b=b.strip()
b=b.strip()
while len(b)!=39:
b+=' '
b+=':'
print(len(b))
a=b+b+'\n'
m=open('目标.txt','w')
m.writelines(a)
m.close()
print打印的都是40,可文本对不齐,如下:
Digital Intermediate by :EFILM
Supervising Digital Colorist :STEVEN J. SCOTT
Second Colorist :ANDREW FRANCIS
Digital Intermediate Producer :LOAN PHAN
DigitalIntermediate Editor :DEVON MILLER 我这里测试是可以对其的
可能是显示的空格长度与字母占位长度不一致导致的
Digital Intermediate by :EFILM
Supervising Digital Colorist :STEVEN J. SCOTT
Second Colorist :ANDREW FRANCIS
Digital Intermediate Producer :LOAN PHAN
DigitalIntermediate Editor :DEVON MILLER
可能是你字体的问题所以看起来没对齐,实际是对齐的,我这边是对齐的 建议用等宽字体试试吧 应该使用等宽字体Consola
页:
[1]