1. 程式人生 > >python2.7簡明之自動備份指令碼

python2.7簡明之自動備份指令碼

問題原因:

用的是window8 python 2.7.1,發現zip命令無法識別,無法壓縮,檢視知乎,百度之後

解決方法:

1下載WinRAR,安裝到C:\Windows\System32下面

2將安裝的檔案複製到Python27/example下面
3程式碼

import os
import time
source=[r'C:\Python27\example\cat.py',r'C:\Python27\example\for.py']
target_dir=r'C:\Python27\example\d'
target=target_dir+os.sep+time.strftime('%Y%m%d%H%M%S')+'.rar'
print source
print target
rar_command= '"C:\Python27\example\WinRAR.exe" a %s %s' %(target,' '.join(source))
print(rar_command)
print(os.system(rar_command))
if os.system(rar_command)==0:
print 'Successful ',target
else:
print 'fail'

4顯示結果

5檢視壓縮包


 下面是自學筆記,大部分是截圖

  • 序列

 

示例:

                       

                   

  • 物件

示例:

                            

  • 儲存
示例:

                            

   Shoplistfile檔案的名字是shoplist.date,Shoplist是一堆資料,開啟shoplistfile,可寫呼叫儲存器模組的dump函式,把物件儲存到開啟的shoplistfile檔案中

    關閉,刪除,開啟shoplistfile檔案,取回物件shoplistfile