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()
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