5. python modules and python modules
If _ name __= = '_ main _': Usage:
When we run the module file in the command line, the Python interpreter puts a special variable__name__Set__main__If you importhelloModule,ifThe Judgment will fail. ThereforeifThe test allows a module to
Time datetime and random in common Python modules, and time in python modules
This section outlines:
I. Module introduction:
Module, which implements a set of code for a specific function with a single worker code.
Similar to functional programming and process-oriented programming, functional programming completes a f
Introduction to two built-in modules in Python and two built-in modules in python
After using Python for a while, we can say that the basic unit of Python is the module. When using the module, we generally use the import Statemen
I. Definition and type of module1. DefinitionA module is a collection of code that implements some function with a bunch of code, usually one or more functions are written in a. py file, and if some features are complex to implement, then you need to create N. py files, and the collection of N. py files is a module2. Type1) custom modules, write your own. py file collection that implements some of your own functional requirements2) Imported ModulesAft
Python functions and modules, Python function modulesIntroduction
Function concepts also exist in python. Standard functions can be called built-in functions, which can be called directly by function names. However, some other built-in functions cannot be called directly through the function name, such as the floor fun
First, what is the module In order to write maintainable code, many functions are grouped into separate files, so that each file contains relatively few code, and the programming language uses this kind of organizational method. In Python, a. py file is called a module.Ii. What are the benefits of using modules?
The greatest benefit is that the maintainability of the code is greatly improved. Seco
Python third-party modules install third-party modulesIn Python, the installation of a third-party module is done through the Setuptools tool. Python has two package management tools that encapsulate Setuptools: Easy_install and Pip. Currently, it is recommended to use PIP.If you are using Mac or Linux, install the PIP
, not just returns false24.os.path.getsize (' homework.py ')Get File size25.os.path.join (' d:/', ' python/', ' MLL ', ' test.py ')Stitching into a path26.os.walk (R ' D:\syz_python\code\day6\test ')Get content under DirectoryAbs_path the absolute path of the current loopDir directory below all folders []All files under file directory []Second, sys module1.sys.pathPath is a directory listing from which Python
,age): #zip to compress multiple lists together Print (NAME,SE,AG)If the list element is not as many, the loop is minimal.Map #循环帮你调用函数Filter3 modulesA python file is a module3.1 Standard ModulesStandard modules: Python comes with modules that are standard modules, which are
interpreter and gives control to the executed program.The OS.SEP variable is used primarily for separators in the system path.Windows system through is "\ \", Linux class system such as Ubuntu separator is "/", and Apple Mac OS system is ":".Iv. OS module Case code DemoSummary:OS module in the system files and directory operations used more, is also our common module, we must master the knowledge, which is a typical Python standard cross-platform mod
Since some PDF files need to be downloaded from a Web page, there are hundreds of PDF files to download, so it is not possible to download them manually. Python has the relevant modules, so I wrote a program to download the PDF file, and by the way, I was familiar with Python's Urllib module and ULRLLIB2 module.
1, the problem description
A PDF file containing hundreds of papers from the http://www.cvpape
JSON and pickle modules, two modules for serializationJSON module for conversion between a string and a Python data typePickle Module for conversion between Python-specific types and Python data typesTwo modules, all available wit
modulesIn Python, the installation of a third-party module is done through the Package management tool PIP.If you are using Mac or Linux, install the PIP itself this step can be skipped.Commands for installing Pillow: PIP3 Install PillowIf you do not want to use PIP one installation time and effort, but also need to consider compatibility. Can be directly used anaconda, which is a python-based data process
In Python, common modules related to time processing are: Time,datetime,calendar (seldom used)First, in Python, there are usually several ways to represent time:
Time stamp
Formatted time string
Tuple (Struct_time) a total of nine elements
Ii. definition of severalUTC (coordinated Universal time, world co-ordination) is GMT, world standard T
Time and datetime modules in Python are modules in the temporal contextOne, Time moduleThere are three types of time-performance formats in the Times module:1, timestamp: Timestamp, time stamp represents the offset in seconds from January 1, 1970 00:00:002, Struct_time: Time tuple, a total of nine element groups.3. Format time: Formatting times, formatted structu
j in IP: # # #循环列表Myping (j)#################################################Multi-process [each process, has its own memory]Multithreading [Share a piece of memory]Multi-threaded ping host faster than above#!/usr/bin/python#coding: Utf-8Import threadingImport subprocessdef myping (x):M=subprocess.call (' ping-c2%s >/dev/null '%x,shell=true)If m==0:Print '%s is up '%xElsePrint '%s is down '%xip=[' 176.121.205.%s '%i for I in Xrange (1,254)]For-J in I
1.Python built-in modules and third-party modules
Built-in modules:
Python, after installing Python, has its own library, called Python's built-in library.Built-in modules
path into directory and file name two tuples returnedOs.path.dirname (PATH)#returns the directory of path. is actually the first element of Os.path.split (path)Os.path.basename (PATH)#returns the last file name of path. If path ends with a/or \, then a null value is returned. The second element of Os.path.split (path)Os.path.exists (PATH)#Returns true if path exists, false if path does not existOs.path.isabs (PATH)#returns True if path is an absolute pathOs.path.isfile (PATH)#returns True if pa
Python primarily uses the logging module for log processingMany programs have logging requirements, and the log contains information that has a normal program Access log, there may be errors, warnings and other information output, Python's logging module provides a standard log interface,You can store logs in various formats through it, logging logs can be divided into debug (), info (), warning (), error (), critical () 5 levels,Log level:DEBUGINFOWA
Regular expression crawler applications (Campus beauty net)1 ImportRequests2 ImportRe3 ImportJSON4 #定义函数返回网页的字符串信息5 defgetpage_str (URL):6page_string=requests.get (URL)7 returnPage_string.text8 9Hua_dic={}Ten defrun_re (URL): #爬取名字, school, and number of people you love OneHua_str=getpage_str (URL) AHua_list=re.finditer ('', Hua_str,re. S) - forNinchhua_list: #将名字, school, and number of favorites write a dictionary -Hua_dic[n.group ('name')]=[n.group ('School'), N.group (' like')] the
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.