我显然还是一名初学者,但我创建了一个解析文件,它通过一个文本文件并生成一个我需要的文件。Python脚本可以在命令行中运行,但不能在运行.py文件时运行
物流并不像明显发生的那样重要。
import fileinput;
for lines in fileinput.FileInput("c:/manhattan.txt", inplace=1):
lines = lines.strip();
if lines == '': continue;
print(lines);
source = open('c:/manhattan.txt','r');
hrt = open('c:/test.hrt','w');
currentline = str(source.readline());
currentline.lstrip();
workingline = '';
while currentline[0] != " ":
if currentline[0].isdigit() == True:
if currentline[0:3] == workingline[0:3] and len(workingline)<160:
workingline = workingline + currentline[4:7];
currentline = str(source.readline());
currentline.lstrip();
else:
hrt.write(('\x01' + 'LOC01LOC' + workingline).ljust(401,' ') +'\n');
workingline = currentline[0:7].replace(';','E');
currentline = str(source.readline());
currentline.lstrip();
else:
currentline = str(source.readline());
currentline.lstrip();
hrt.write(('\x01'+'LOC50US1 A*').ljust(401,' ' +'\n');
hrt.write(('\x02'+'LOCSUNSAT00:0023:5960 60 99990.00 0.00').ljust(401,' ')+'\n');
hrt.write(('\x02'+'US SUNSAT00:0023:5960 60 99990.03 0.03').ljust(401,' ') +'\n');
hrt.close();
source.close();
它工作正常,在Python命令行,但在运行.py文件时,它简化版,写最后三行文件。
任何想法?
有没有错误? –
'其他链接\ n' '讨论\ n' '喜欢这个网站?我们通过PayPal接受捐赠\ n ' ' 回溯(最近最后一次通话): 文件 “”,1号线,在 IndexError:字符串索引超出范围 >>> hrt.write的((' \ x01'+'LOC50US1 A *')。ljust(401,'')+'\ n'); >>> hrt.write(( '\ X02' + 'LOCSUNSAT00:0023:5960 60 99990.00 0.00'。)LJU ST(401, ' ')+' \ N'); >>> hrt.write(( '\ X02' + 'US SUNSAT00:0023:5960 60 99990.03 0.03')LJU ST(401, ' ')+' \ N'); >>> hrt.close(); >>> source.close(); >>> –
user2274589