1.windows 7:
Install python2.x or 3.x, programming languages have different places, need attention, the web is mostly 2.x tutorials.
After CMD, before running Python xxx.py, you need to set the environment variable, write the path name of the Python installation to the variable value, the variable name or path
I encountered the situation is in the Py file Direct shortcut key Fn+f5 Run, packaging failed, but in cmd python xxx.py normal run package script, the code is as follows:
The code is as follows |
Copy Code |
#-*-coding:cp936-*- Import OS Import time |
# in the list, specify the file name and or directory that you want to back up
Source = [R ' "D:kankan"]
# Backup to the following directory
The code is as follows |
Copy Code |
Target_dir = ' h:\ ' |
# Backup to zip file, file name is: The time of day and month. zip
The code is as follows |
Copy Code |
target = Target_dir + ' backup ' + '. Zip ' |
# Compress files with winrar command line, provided winrar is in Windows XP path
The code is as follows |
Copy Code |
Zip_command = "rar A%s%s"% (target, '. Join (source)) |
# Run this backup program to back up
The code is as follows |
Copy Code |
If Os.system (zip_command) = = 0: print ' successful backup to ', target Else print ' Backup failed! ' |
Note When using the RAR a command to package files or folders, you need to ensure that the environment variables have been configured, path and RAR installation path, Control Panel-system-advanced-environment variables-system variables
2.linux Ubuntu
The code is as follows |
Copy Code |
#-*-coding:cp936-*- Import OS Import time |
# in the list, specify the file name and or directory that you want to back up
The code is as follows |
Copy Code |
Source = [R ' "/home/xiaonuo/somefile"] |
# Backup to the following directory
The code is as follows |
Copy Code |
Target_dir = '/home/xiaonuo/zipfile ' |
# Backup to zip file, file name is: The time of day and month. zip
The code is as follows |
Copy Code |
target = Target_dir + ' backup ' + '. Zip ' |
# Compress files with winrar command line, provided winrar is in Windows XP path
The code is as follows |
Copy Code |
Zip_command = "Zip-qr%s%s"% (target, '. Join (source)) |
# Run this backup program to back up
The code is as follows |
Copy Code |
If Os.system (zip_command) = = 0: print ' successful backup to ', target Else print ' Backup failed! ' |
Linux version most of the default installed Python, in the terminal directly into the Python (path) xxx.py can execute the written PY code, Zip command is the system itself, do not need multiple.