成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Python教程中10.4 備份腳本代碼中需注意的地方

開發(fā) 后端
在Python的實際應(yīng)用中,你是否覺得Python要比其他的編程語言要好的多?但是在實際的應(yīng)用中也有需要注意的地方,比如Python教程在10.4 備份腳本——版本四的代碼。

你對Python編程語言的實際應(yīng)用是否感興趣?你是否了解其強大的實際運用功能?如果你對這些東西都特別的感興趣的話,你就可以瀏覽以下的文章對其進行相關(guān)的了解,以下是文章的具體介紹。

Python教程

在例10.4 備份腳本——版本四的代碼中有些需要注意的地方。

  1. #!/usr/bin/python  
  2. # Filename: backup_ver4.py  
  3. import os  
  4. import time  
  5. # 1. The files and directories to be backed up are 
    specified in a list.  
  6. source = [‘/home/swaroop/byte’, ‘/home/swaroop/bin’]  
  7. # If you are using Windows, use source = 
    [r'C:\Documents', r'D:\Work'] or something 
    like that  
  8. # 2. The backup must be stored in a main
     backup directory  
  9. target_dir = ‘/mnt/e/backup/’ # Remember to 
    change this to what you will be using  
  10. # 3. The files are backed up into a zip file.  
  11. # 4. The current day is the name of the subdirectory
     in the main directory  
  12. today = target_dir + time.strftime(‘%Y%m%d’)  
  13. # The current time is the name of the zip archive  
  14. now = time.strftime(‘%H%M%S’)  
  15. # Take a comment from the user to create the name 
    of the zip file  
  16. comment = raw_input(‘Enter a comment –> ‘)  
  17. if len(comment) == 0: # check if a comment was entered  
  18. target = today + os.sep + now + ‘.zip’  
  19. else:  
  20. target = today + os.sep + now + ‘_’ + \  
  21. comment.replace(‘ ‘, ‘_’) + ‘.zip’  
  22. # Notice the backslash!  
  23. # Create the subdirectory if it isn’t already there  
  24. if not os.path.exists(today):  
  25. os.mkdir(today) # make directory  
  26. print ‘Successfully created directory’, today  
  27. # 5. We use the zip command (in Unix/Linux) to put 
    the files in a zip archive  
  28. zip_command = "zip -qr ‘%s’ %s" % (target, ‘ 
    ‘.join(source))  
  29. # Run the backup  
  30. if os.system(zip_command) == 0:  
  31. print ‘Successful backup to’, target  
  32. else:  
  33. print ‘Backup FAILED’  

關(guān)于Python教程的相關(guān)代碼,文中提到“我還希望有的一個優(yōu)化是使用tar命令替代zip命令。這樣做的一個優(yōu)勢是在你結(jié)合使用tar和gzip命令的時候,備份會更快更小。如果你想要在Windows中使用這些歸檔,WinZip也能方便地處理這些.tar.gz文件。tar命令在大多數(shù)Linux/Unix系統(tǒng)中都是默認可用的。Windows用戶也可以下載安裝它。

命令字符串現(xiàn)在將成為:

  1. tar = ‘tar -cvzf %s %s -X /home/swaroop/excludes.txt’
     % (target, ‘ ‘.join(srcdir)) 

需要補充的是Windows用戶安裝完LibArchive后命令為bsdtar,而且若想使用-z這個選項,還需安裝gzip軟件。

代碼中的

  1. target = today + os.sep + now + ‘.zip’ 

改為

  1. target = today + os.sep + now + ‘.tar.gz’ 

使用

  1. bsdtar -cvzf %s %s -X /home/swaroop/excludes.txt’ % (target, ‘ ‘.join(source)) 

 

英文原版已經(jīng)沒有用tar替換zip的內(nèi)容了,提出建議用Python標準庫中zipfile和tarfile來重寫ver5。 以上就是對Python教程相關(guān)的內(nèi)容的介紹,望你會有所收獲。

【編輯推薦】

  1. Python源碼分析的實際相關(guān)操作步驟解析
  2. Python安裝的步驟操作其實是件很容易的事
  3. Python語言功能中的宏編程語言的實際操作方案介紹
  4. mod_python在性能上要優(yōu)于傳統(tǒng)CGI的緣由
  5. Python中文轉(zhuǎn)換url編碼的實際操作步驟介紹
責任編輯:佚名 來源: 博客園
相關(guān)推薦

2010-03-23 13:50:24

python教程

2013-04-07 11:31:05

云計算合同

2013-05-08 09:14:35

網(wǎng)絡(luò)維護網(wǎng)吧網(wǎng)管

2010-09-25 17:57:48

項目管理

2010-10-08 15:58:22

IE JS

2010-07-26 15:30:43

面試

2011-05-05 14:27:17

噴碼機耗材

2011-07-01 15:27:29

網(wǎng)站優(yōu)化

2010-10-08 08:59:26

2011-07-03 23:40:54

友情鏈接

2015-04-16 16:42:11

私有云云部署

2010-05-31 10:55:08

Nagios mysq

2009-07-20 15:37:09

iBatis like注入漏洞

2011-03-31 16:24:16

cacti監(jiān)控

2023-09-14 11:45:48

2011-06-24 09:34:38

外鏈SEO

2010-08-23 16:31:33

CSS

2017-07-31 09:53:31

2023-08-28 10:54:09

容器Docker

2016-09-26 10:36:17

點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 一级一片在线观看 | 免费在线视频一区二区 | 亚洲国产一区视频 | 精品一区二区三区不卡 | 欧美日韩国产一区二区三区 | 久久精品国产免费 | 婷婷五月色综合香五月 | 九九热在线视频观看这里只有精品 | 麻豆久久精品 | 四色成人av永久网址 | 精品久久久久一区二区国产 | 成人精品一区二区 | 免费观看成人av | 精品国产一区久久 | 国产一区二区美女 | 久久中文字幕一区 | 伦理二区| 欧美一级网站 | av在线免费网站 | 国产露脸国语对白在线 | 国产专区在线 | 久久精品99 | 午夜影院在线观看 | 久久亚洲综合 | 最新黄色毛片 | 久久91精品国产一区二区三区 | 中文字幕影院 | 国产精品国产三级国产aⅴ中文 | 在线成人| 亚洲人成人一区二区在线观看 | 欧美精品三区 | 自拍偷拍第一页 | av免费网站在线 | 成人精品一区二区 | 精品欧美一区免费观看α√ | 亚洲精品一区二区网址 | 亚洲一区二区电影网 | 在线a视频网站 | 婷婷福利视频导航 | 在线观看免费av片 | 午夜视频一区 |