Home:ALL Converter>Python is not writing to a file for some reason

Python is not writing to a file for some reason

Ask Time:2014-09-04T06:12:49         Author:zooted

Json Formatter

Is there a reason why this is code is not writing to a file. Everything else works on this except for the writing part I know I need to close the file but I'm not sure how?

import os
import sys
import csv
import pysftp as sftp

with open('c:/Python27/log_07032014_1512.txt','r') as inf,    
open('C:/Python27/Errors.txt','w')as outf:
reader = csv.reader(inf)
writer = csv.writer(outf)
for line in inf:
    if 'Error' in line:
        print line

def sftpExample():
try:
    s = sftp.Connection('***.***.***.***', username = '******', password = '****')
    remotepath ='/home/*****/BOA.txt'
    localpath = 'C:/Python27/Errors.txt'
    s.put(localpath,remotepath)

    s.close()
except Exception, e:
    print str(e)

sftpExample()

Author:zooted,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25654449/python-is-not-writing-to-a-file-for-some-reason
ventsyv :

Unless I'm missing something, I don't see you writing to the file:\n\nfor line in inf:\n if 'Error' in line:\n writer.writerow(line)\n\n\nIf you want to check if any particular \"column\" contains error, as Jon Clements suggests below, you should loop over the csv reader output not over the raw file:\n\nfor line in reader:\n if 'Error' in line:\n writer.writerow(line)\n",
2014-09-03T22:18:26
yy