2012-11-05 16 views
0

我想通過使用python必須從服務器/網站獲取的標準txt文件來始終更新列表。如何使用Python從服務器/網站導入文件/列表

women =["Dare1","Dare2","Dare3","Dare4","Dare5","Dare6"] 

    men = ["Dare1","Dare2","Dare3","Dare4","Dare5","Dare6"] 

然後,一旦程序被重新打開時,它搶更新TXT

women =["Dare1","Dare2","Dare3","Dare4","Dare5","Dare6","Dare7"] 

    men = ["Dare1","Dare2","Dare3","Dare4","Dare5","Dare6"] 
+0

如果我正確理解您的問題,只需將您的代碼鏈接到Web服務器上的文件位置....每次打開它。使用urllib。 – enginefree

+0

請勿使用urllib。請求的API將會更加快樂。 http://docs.python-requests.org/en/latest/ – hughdbrown

回答

0

從而產生這個文本文件/目標服務器上自動更新?如果您知道顯示此文本文件的網址,就像使用python的urllib模塊在您自己的系統上執行urlretrieve模塊來檢索它並實現cron一樣簡單,以便定期運行該python腳本。

下面是它的用法的例子: -

fName = "CFE_{0}{1}_VX.csv".format(m_codes[month],str(year)[-2:]) 
save_path = os.path.join(path, fName) 
if os.path.exists(save_path) or forceDownload: 
    print 'File already downloaded, skipping' 
    return 

urlStr = "http://cfe.cboe.com/Publish/ScheduledTask/MktData/datahouse/{0}".format(fName) 
print 'Getting: %s' % urlStr 
try: 
    print save_path 
    urlretrieve(urlStr, save_path) 
except Exception as e: 
    print e 

在這種情況下,我下載來自芝加哥期權交易所csv文件。

+0

謝謝,這將得到正確的道路。我在Python中是一個新手,所以服務器的東西是品牌嶄新的。 – c0rruptbytes

+0

沒有汗水。讓我知道這是您需要的還是您有任何其他問題。 –

相關問題