. Timedrotatingfilehandler (' Web.log ', when= ' s ', interval=3,backupcount=5) Logger.addhandler (File_handler) file_ Formatter = logging. Formatter ('% (name) s-% (asctime) s-% (levelno) s-% (message) s ') File_handler.setformatter (file_formatter) logger.debug (' The Debug ') logger.info (' the info ') logger.warning (' The Warning ') logger.error (' the error ') logger.critical (' The Critical ')Generates one every 5 seconds and needs to be run before it is generatedRun resultsGradeLogger is
:\\pycharm\\ Learning \\day29\\userinfo ')]IncreaseConfig.read ('Userinfo.ini', encoding='Utf-8') config.add_section ('IP')#Adding nodesPrint(Config.sections ())#[' Path ', ' IP ']Config.set ('IP','IP','192.168.1.1')#Add a configuration item to a nodeConfig.set ('Path','UserInfo','None')#Modifying configuration ItemsPrint(config['IP']['IP'])#192.168.1.1Print(config['Path']['UserInfo'])#NoneConfig.write (Open ('Userinfo.ini','W', encoding='Utf-8'))#to re-write the modifications back to the fileDe
The Python module is divided into system-built modules, third-party modules, and user-written modulesBy default, Python's third-party modules are installed in the Python installation directory under site-packages and stored as files or directoriesThe user module, the program modularization to distinguish the function a
I. Overview of OS ModulesThe Python OS module contains common operating system features. For example, copying files, creating files and folders ...Second, common methods1, Os.listdir () returns all file and directory names under the specified directory.2, Os.remove () delete a file.3, Os.system () run the shell command.4. The Os.path.split () function returns the directory name and file name of a path5, Os.
Web CrawlWeb sites use HTML descriptions, which means that each Web page is a structured document. Sometimes it is useful to get data from it while maintaining its structure. Web sites do not always provide their data in an easy-to-handle format, such as CSV or JSON.
This is the time for the web to crawl out. Web crawling is the practice of using a computer program to collect and organize Web page data into the desired format while preserving its structure.
lxml and requestslxml (http://lxml.de
. Streamhander (sys.stdout) Print_handler.setformatter (Formatter) # Add the specified log processing method to the instance, you can add multiple log processing methods Logger.addhandler ( File_handler) # Responsible for storing to file Logger.addhandler (Print_handler) # is responsible for printing to the screen # call logger, while the screen is displayed , save the log to file Logger.debug ("This is a Debug test") Logger.info ("This is an info test") logger.waring ("This is a Waring test") L
#!/usr/bin/env python#-*-coding:utf-8-*-__author__="Loki"#usage:hashlib ModuleImportHashlibImport Time#wrapper function Calc Length and use timedefLen_type_tools (res):defWrapper (*args, * *Kwargs): Cur_time=time.time () len_res= Len (res (*args, * *Kwargs)) Result= Res (*args, * *Kwargs) End_time= Time.time ()-Cur_timePrint('Primary HASH result length is {0}, use time {1:.2f}'. Format (len_res, end_time))returnresultreturnwrapperdefmenu_list (): Func
Random moduleRandom module for dealing with random problems.Import Random # random integers Print (Random.randint (0, 9)) # a random integer between 0 and 9 Print (Random.randrange (1, 2)) # 1 to 9 randomly an odd number# Random Decimals Print (Random.random ()) # random one decimal between 0 to 1 Print (Random.uniform (1, 3)) # random one decimal between 1 to 3# Random return Print ' a ' ' b '])) # randomly select a return from the object Print
whether the specified path is an absolute path
Isdir (PATH)
Determine if the specified path exists and is a directory
Isfile (PATH)
Determines whether the specified path exists and is a file
Islink (PATH)
Determines whether the specified path exists and is a symbolic link
Ismount (PATH)
Determine if the specified path exists and is a mount point
Samefile (path1,PAHT2)
Determine if the two paths of pat
/down.php ') print urljoin1
Code Run Result:C:\Python27\python.exe c:/users/lee/desktop/d/pycharmprojects/untitled/test.pyhttp://www.sina.cn/file/down.phphttp://www.sina.cn/cc/file/down.php
Third, urlparse function and urlsplit function useThe main analysis is urlstring, which returns a tuple containing 5 string items: protocol, location, path, query, fragment. When Allow_fragments is false, the tuple's group after a project is always empty, regardless of w
>>> Random.randomrange (1,10)#returns a random number between 1-10, excluding>>> Random.randint (1,10)#returns a random number between 1-10, including ten>>> random.randrange (0, 100, 2)#randomly select even numbers between 0 and 100>>> Random.random ()#returns a random floating-point number>>> Random.choice ('Abce3#[email protected]')#returns a random character in a given data set'#'>>> Random.sample ('Abcdefghij', 3)#Select a specific number of characters from multiple characters['a','D','b']#
) [01,12]
%j
Day of the year [001,366]
%m
month [1,12]
%M
minutes [0,59]
%p
Morning and afternoon [AM,PM]
%s
seconds [00,61]
%u
The number of weeks in a year (Sunday as the first day of the week) as a decimal number [00,53], the first Sunday of the year before all days are considered to be in the No. 0 week
%w
Week, results for numbers [0 (Sunday), 6]
Python shutil module and Pythonshutil Module
Import shutil
1. shutil. copy (source, destination)
Copy the source file to destination. Both parameters are in string format.
2. shutil. copyfilr ()
Copy the source file content to the target file. If the target file does not exist, an error is generated.
3. shutil. copytree (source, destination)
Copy the entir
, in fact Timedelta can support the addition and subtraction of the following parameters, such as weeks, hours, minutes# days=0, Seconds=0, Microseconds=0,milliseconds=0, Minutes=0, Hours=0, weeks=0):#Current_time = Datetime.datetime.now ()Print (Current_time)#替换为某年, one month, one dayPrint (Current_time.replace (2016,1,3))Print (Current_time.replace (2016,3))Print (Current_time.replace (2015))# 2016-01-03 23:01:54.095012# 2016-03-07 23:01:54.095012# 2015-04-07 23:01:54.095012#两个时间还可以做比较# gtime
Os.listdir (dirname): Lists directories and files under DirName os.getcwd (): Get current working directory Os.curdir: Returns the current directory ('. ') Os.chdir (dirname): Change the working directory to Dirnameos.path.isdir (name): Determine if Name is a directory, name is not a directory and return Falseos.path.isfile (name): Determine if name is a file, does not exist name also returns Falseos.path.exists (name): Determine if there is a file or directory Nameos.path.getsize (name): Get th
This article describes how to use the Pythonemail module and the smtplib library to send emails. you can use the Python email module to send emails with attachments.
SMTP (Simple Mail Transfer Protocol)The Mail Transfer Agent (MTA) program uses the SMTP protocol to send emails to the recipient's Mail server. The SMTP protocol can only be used to send mails and c
Extended Python module series (4) ---- handling of reference counting problems, python ----
Taking on the above, we found that when using Python C/C ++ API to expand the Python module, we always have to consider the reference coun
First, the understanding moduleWhat is a module: A module is a file containing Python definitions and declarations, with the suffix of. py appended to the file name, but in fact the import loaded module is divided into four general categories:1. Code written using Python (.
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.