【发布时间】:2014-01-21 19:07:12
【问题描述】:
目前用户的输入被保存为计算机上的文件,我想也希望将它上传到我的 ftp 服务器,我已经让它工作了,但文件中没有任何内容,很可能因为我是编程新手,所以很容易出错,谢谢
quotation = input("Do you want to save a quotation? ")
if (quotation == "yes") :
quotationName = input("What do you want to save the quotation as? ")
text_file = open("{}.txt".format(quotationName),"w") #(w) opens files in write
text_file.write ("The total lawn area is {}\n".format(totalAreaLawn))
text_file.write ("The total for the lawn is £{}\n\n".format(totalCostLawn))
text_file.write ("The total concrete area is {}\n".format(totalAreaConcrete))
text_file.write ("The total for the concrete is £{}\n\n".format(totalCostConcrete))
text_file.write ("The total wooden deck area is {}\n".format(totalAreaWoodenDeck))
text_file.write ("The total for the wooden deck is £{}\n\n".format(totalCostWoodenDeck))
text_file.write ("The total rectangular pond area is {}\n".format(totalAreaRectangularPond))
text_file.write ("The total for the wooden deck is £{}\n\n".format(totalCostRectangularPond))
text_file.write ("The total number of water features needed is {}\n".format(numberOfWaterFeatures))
text_file.write ("The total for the water features is £{}\n\n".format(totalCostWaterFeatures))
text_file.write ("The total number of garden lights needed is {}\n".format(numberOfGardenLights))
text_file.write ("The total for the garden lights is £{}\n\n".format(totalCostGardenLighting))
#text_file.close()
ftpconnect = ftplib.FTP('landscapegardening.freeiz.com','a6011438','L0g1tecH')
saveDirectory = '/public_html/Quote'
ftpconnect.cwd(saveDirectory)
fileSend = open("{}.txt".format(quotationName),'rb')
ftpconnect.storbinary('STOR {}.txt'.format(quotationName), fileSend)
fileSend.close()
ftpconnect.quit()
print("Quotation saved")
【问题讨论】: