0
我試圖寫一個HTML文件,然後使用下面的代碼把它上傳到我的網站:任何方式來提高關閉文件的速度?
webpage = open('testfile.html',"w")
webpage.write(contents)
webpage.close
server = 'ftp.xxx.be'
username = 'userxxx'
password = 'topsecret'
ftp_connection = ftplib.FTP(server, username, password)
remote_path = "/"
ftp_connection.cwd(remote_path)
fh = open("testfile.html", 'rb')
ftp_connection.storbinary('STOR testfile.html', fh)
fh.close()
的問題是.close
命令似乎比FTP連接,那就是文件慢通過ftp發送的是空的。在執行ftp後幾秒鐘,我在我的PC上正確地在本地看到該文件。
任何暗示確定在FTP開始之前完成.close
(除了使用time.sleep()
)?
運行的Python的3.xx上W7pro
您在第一次關閉後忘記了parens,所以實際上並沒有調用'close()',只是引用它。使用'webpage.close()'。 – glibdud
是的,一定是它,感謝注意! – ON5MF