有沒有原因,這是代碼沒有寫入文件。除了寫作部分之外,其他一切都適用於此我知道我需要關閉該文件,但我不確定如何?由於某種原因Python沒有寫入文件
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()
你能解決你的代碼縮進? – 2014-09-03 22:15:05