1. Python File Processing
Today, we found that when processing files on Mac OS X, three modes are 'R', 'w' ('R + ', 'W +'), and 'A '.
The 'A' mode must be used for append on Mac. It seems that 'W + 'can be used in the past.
F. Close () serves as the final storage disk.
Compressed file:
Import OS
Import zipfile
Import time
# Compressing Directories
Source_dir = r 'f: web'
# Generate file names by Time
Target_file = time. strftime ('% Y % m % d % H % m % s') + '.zip'
Myzipfile = zipfile. zipfile (target_file, 'w') # compress all files, including subdirectories
For root, dirs, files in OS. Walk (source_dir ):
For vfilename in files:
Filename = OS. Path. Join (root, vfilename)
Myzipfile. Write (filename, filename, zipfile. zip_deflated)
# Compression completed
Myzipfile. Close ()
2. Python bool type
AlthoughBoolInPython build-in FunctionBut it is actually a class and has two unique instances, true and false, so it seems that they are neither true/false nor true/false for a reason. Bool is a subclass of int and cannot be inherited.
From the function perspective, bool can accept any parameter, number, character, or no parameter. Based on the parameter, bool returns true or false through the test and judgment process.
See the following:
>>> If True:
Print " OK "
OK
>>> If False:
Print " OK "
>>>