Python File Processing bool type

Source: Internet
Author: User

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 "
 
>>>  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.