python输出指定编码的逐行文件

1 在swat的结果文件中,需要关注某一个指定reach的变化情况。附代码为:
下面展示一些 内联代码片

// A code block
var foo = 'bar';
// An highlighted block
var foo = 'bar';
#import 
import os
import numpy as np
import datetime
import xlrd,xlwt
import re
file_obj = open('C:\\Users\\Administrator\\PycharmProjects\\Test030101\\output.rch')
lines = file_obj.readlines()

with open ("C:\\Users\\Administrator\\PycharmProjects\\Test030101\\dataoutput2.txt", "w") as fa:
    fa.write('reach' + '    ' + 'num' +'    '+ 'GIS' + '      ' +'flow_in'+ '      ' + 'flow_out'+ '\n')
    for line in lines:
        artlists_11 = [i for i in line.strip()]
        if artlists_11[9:10] == ['1'] and artlists_11[10:11] == ['5']:
            artlists_12 = artlists_11[:62]
            #artlists_13 = str(artlists_12)

            fa.writelines(artlists_12)
            fa.writelines("\n")
    fa.close()
    ...
   

2 在写入文件之前,print输出if判断语句,很简单。
3 补充知识,re.findall()利用正则表达式查找字符,
4 出现错误罗列
(1)IndentationError: unindent does not match any outer indentation level--
代码与任何外部缩进级别都不匹配。
(2)a = [0,1,2,3,4,5,6,7,8,9]
        a[ : :4]  #输出以4为间隔的列表
(3)'\d'非数字
(4)TypeError: 'NoneType' object is not subscriptable -->
 描述:变量使用了系统内置的关键字list
解决:重新定义下这个变量

(5)python输出指定编码的逐行文件_第1张图片

(6)python输出指定编码的逐行文件_第2张图片

你可能感兴趣的:(python输出指定编码的逐行文件)