Print directory content, including the size and modification time of each file
For simplicity the following version only prints the entry names without printing their full path
Typeerror:print_dir_info () Missing 1 required positional argument
Rename a move copy delete file
Rename moved copy Delett file
Shutil module includes operation file operation Shutil.move Renaming a function
function Shutil.move Rename a file to move one file to another directory
Shutil.move ("Old Mail.txt", "" ")
Os.rename os renaming and moving files functions
Os.rename may not be able to specify a directory name as the target
Cannot move a file to a disk or file system outside the forest
Shutil copy function copies a file to a file with a new name or to a new directory
Delete the simplest operation Os.remove
Os.move ()
Chown chmod Modifying the permissions of a file directory
Os.chmod (' fileName ', ' permission representation ')
Mkdir
Os.mkdir ()
Create an empty directory
Os.mkdir () The parent directory must exist when creating an empty directory
Mkdir-p
Os.mkdir ()
Os.makedirs () recursively create a directory tree
Os.rmdir () Delete directory Delete empty directory
Os.rmdir
Shutil.rmtree can delete a directory if it contains other files and subdirectories
Shutil.rmtree
Wildcard Globbingg means expanding the wildcard in file name mode
The name Glob function is provided in the module Glob to enable the wildcard function of the directory contents.
Glob.glob function Accept mode as input
Returns a list of all matching file names and path names
Wildcard and case sensitivity
m* can match all file names and files whose names start with M m are generally case-insensitive
Wildcard characters that can be used in a wildcard mode
* 0 or more characters or any *.M
? Any single character??? Match exactly contains 3 character names
[...] Any one of the characters listed in square brackets [aeiou]
[!..] Any one character that does not appear in square brackets
Use a range of characters between square brackets
[M-p] Mnop any one letter
[!0-9] matches any character other than a number
Match any one
? Any single character
* 0 or more characters
Square brackets
Wildcard is a convenient way to select a set of similar files for a file operation
Glob.glob ("\\*.txt")
Glob.glob ("\ \")
Glob.glob ()
Python's most attractive point is that it offers a wide range of built-in functions and modules
Python provides a standard module to better understand their
Simple anonymous functions
Filter
Simple anonymous functions
A simple function call is required to tell Python to create a function and use it in the appropriate place instead of referencing it by a name
Lambda receives the list and gives the function definition the standard removal element
Lambda Filter Simple anonymous function
Map Short Circuit loop
List to make a decision list resolution
Used to dereference the list operator
X for x in everything if x% 2 = = 0
Loop iterator
Ability to create iterator special properties
Range
Generating iterators for loops
Loop iterator Step Step
Numeric interval
Create an inclusion that requires all elements of an array to be checked for all elements in a sequence each element consumes some memory range
Avoid problems with large lists
Xrange
Only a few elements of the list are created in memory
Range no longer creates a list but instead changes to an iterator
Xrange
Check the range iterator
Range returns an iterator object that behaves like a list
Pointer dereference *
Dereference a list
XR = range (10) direct call does not return a list to generate a representation of the method it calls
Generates a representation of the method it calls
The dereference operator is accessed using the same list sequence as the dictionary dereference
List sequence tuple dictionary the same dereference operator [square brackets] to access
Returns an iterator object that behaves like a list
An iterator object that behaves like a list
Range generates an object without any methods, without any public methods
Built-in methods can be used like a simple sequence
Like simple sequence use
When you use square brackets to access a list
Essence use square brackets to access a list of tuple dictionaries tell Python to invoke the list tuple dictionary __getitem__ method
The Range object has this private method that can access and dereference like a sequence
When calling range it does not generate a list but tells you how it is generated
Scheduler_default_filters=availabilityzonefilter,ramfilter,computefilter,computecapabilitiesfilter,imageprop
Os.fork immediately call Os.execl to run other programs
OS.EXECL is a command that replaces a running program with a new program
Perform some kind of subtask to run a new program to create a new
Use Os.fork for system calls to tell the computer to copy everything about the currently running program to a newly created individual program to copy about the currently running program
Newly created process-child process Os.fork
The return value is the newly created process in the original process-the parent process ID
The return value is the newly created process in the original process
Process of the newly created process in the original process
One of the most common things to do after calling Os.fork is to call Os.execl immediately to run other programs
OS.EXECL is a command that replaces a running program with a new program
The calling program terminates with a new program instead of the instruction that is running the program
Start a new program Os.spawn
Spawnl
Spawnle
Spawnlp
Spawnlpe
Spawnv
Spawnve
Spawnvp
Spawnvpe
Spawn indicates a specific situation
V indicates the pass-through list vector allows a wide variety of commands to be run in different instances
No need to modify the program
L variables only need a simple parameter list
Use e to pass a dictionary that includes a name and value as a newly created program environment
Requires a new command for the most basic call Os.system ()
Running a program and just want to wait for the end simple use function
Specifically, when a program grows to a great fork, you must copy all of the program's information to a new program.
Use more than one process child process to create process sharing using parent process data use a lot of data
In order to cope with the non-adaptive sub-process
In order to cope with some of the non-adaptive sub-processes complex conditions do not adapt to sub-process complexity
Programs perform many cooperative threads that can exist simultaneously in the same program
Programs perform many cooperative threads that can exist simultaneously in the same program
Cooperative threads can exist in the same program at the same time
Many cooperative threads can exist in the same program at the same time
There are different objects within each thread, different states
Can communicate with each other semi-independent
A convenient way to share Python code between applications
Easy way to share Python code between applications
A module is a file made up of Python statements
A module can define functions and classes that contain simple executable code
Module
Module is just a python source file
Contains variable class functions any other element that Python can use
Dir Function Element module
All attributes of the element will be listed
__builtins__ built-in function class variables
List all attributes of an element
Import an item from Python
From module import item;
In order to import a module, the Python interpreter first looks for a module name that is passed to the import statement by the MODULE.PYY module
Find the module Python interpreter to compile it into a. PYc Sys.path
Python Interpreter Lookup Module search path
Sys.path Find interpreter Find location
Create a module with a function
Python source files
Worth eating
Include function Properties view the properties of a module's imported module to see the function properties in it
Using the module name prefix
Most modules define a collection of related functions or classes
Most modules define a collection of related functions and classes
class methods for saving data and manipulating data
True object-oriented programming (Object-oriented programming)
Programming
Programming
Programming
object-oriented
object-oriented
Oriented oriented
Oriented
Encapsulating inherited polymorphism
Encapsulation classes can hide the internal details and data required to perform a task
Class is able to hide the internal details and data required to perform a task
Class holds the required data
Viewing data is not supported under normal circumstances
Class hides the internal details and data required to perform a task
class provides some manipulation of the data
class provides a way to manipulate the data to hide internal details
Encapsulation is a simplified program technique
Write code that centrally handles individual tasks
Encapsulation hides the complexity
Inheritance means that a class can inherit or access the data and methods defined in the parent class
Inheritance means that a class can inherit or access the parent class
Inheritance means that a class can inherit or access the data and methods defined by the parent class
Conforms to the common sense of classifying a problem area
Both rectangles and circles are shapes
The base class can be shapes
Rectangle class
Rectangle Rectangle
Rectanglee
Shapes
Circle sub-class member
base class writing common code
Base class Writing
base class generic subclasses should be special
Inheritance is often referred to as the specificity of
Polymorphic-Subclasses can override methods to accomplish more specific behavior
Subclasses can override methods to accomplish special behavior
Complete module includes a lot of work
Define errors and exceptions that apply to modules
Errors and exceptions for modules
Module public API for the item module of Chinese herbal medicine output
Defining module-specific errors
Standard Exception class
IOError
Notimplementederror
Defining exceptions for specific problems that may occur with modules
Angrychefexception
An XML parsing exception might be
An XML parsing exception might include the line number where the error occurred
Class Sensitiveartistexcdption (Exception):
Artist sensitive Sensitive
Artist
Class Angrychefexeption ()
* All public methods of the module
Select define those items to export public methods
The Python interpreter uses two methods to determine which items are public
The __ALL__ interpreter uses __all__ to determine which items are public
Interpreter imports all items except items that begin with the name underscore _
Simple creation of a sequence of document strings
Each string corresponds to the name of each item that you want to export from the module, respectively
Meal Module __all__
__all__=[' Meal ', ' angrychefexception ']
Sequence each name the class function exported from the module
Help Display module documentation for any Python module
Document that displays the module's documentation for any Python module
A test function that contains the function of the execution module
Test functions for performing module functions
Test should create a module instance call instance method
Any file that contains Python code can be viewed as a module that can run a module
Do not want the module to run its own Python defines a convention for a module
Module testing should be performed by the modules running themselves
if __name__ = = ' __main__ ':
Test ()
Creating module Modeling
Create a module
Model meals and drinks in a day
Food and drinks
Drinks
How to form a module
Three mechanism mounting modules
Dmg
Create a Python installation file
Distutils
Distutils
Distutils Distribution Utilities
The distribution utility creates a Python installation file
Distribution Utilits
setup.py
Manifest manifest
Application
Directory tree various files for simple search and processing
Simple search processing for various files in the directory tree
Text Processing
Directory tree files simple search and processing applications are called Text processing
Navigating the directory structure with a platform-independent approach
Text processing to find the target text
Data organizes data in a structured way to organize the database in a structured way
Database with well-established indexing and data storage capabilities
If you know what content data resources you want to look for, the information contained in it is not orderly and structured.
Text-processing domain directory navigation regular expression Magic
Directory navigation the areas where different operating systems really bring trouble to simple programs
Unix Windows Mac organizes directories in different ways
Separate sub-directories with different characters
Provides a series of cross-platform tools to perform directory and path operations
Regular expressions are a very simple way to specify a text parser
Handle any number of lines of text
Extracting useful data
192.168.2.0/24 Wired 3-layer switched IP pool
192.168.0.0/24
Navigating the file system
Many different platforms perform daily tasks
OS Os.path
C:\a\f\f
/e/e/r/root/home
Basic coordinates of a directory function
OS.GETCWD () Can consider this function as any language,
Returns a list of directories stored in the specified directory file name and subdirectory
Os.stat ()
OS.GETCWD pwd
Pwd
Os.listdir ()
The value Tuple group gives any information about the file (directory) that may be needed
Inode Stat
St_mode
Mode access permissions for files
Access Modify creation time Create Cttime
Mtime
Splits a path into a component name that conforms to the current operating system returns a tuple is not a list
Split the path to match the current operating system component name
Split the path into a component name that matches the current operating system
Path matching the current operating system
Os.path.join (components)
Normcase Canonical Path case file name case-sensitive
The Windows operating system ignores case when comparing file names
Os.path.normcase ()
Os.walk (Top,topdown = True,onerror = None,followlinks = False)
Top-down, low-to-upper iteration of the directory tree
Create a filenames by dirpath,dirnames
If you want to use a program to process split into a directory path tuple
Join Connect back
Os.stat ('. ')
Search for special types of files
Improved footstep based on found structure
Find new usage of the program Add new feature show Os.walk function
All the heavy work of file system iterations
Unexpected EOF while parsing
Special characters make pattern matching more meaningful special characters general wildcard characters
Match any one of the characters in the string
Specify a native string
Strings that need to be processed
Filter (lambda ss:re.match (r ' xxx ', ss), SS);
SE = Filter ((Lambda To-be-string:re.match (R ' will be matched string ', ss)), SS)
The return value of the function is the data type of the filter class
How to match a period only
Original character
c = Filter ((Lambda s:re.search (R ' x.x ', s)), SS)
* 0 +
. Any square brackets that match a special string
. * any number;
Asert assert assert assertion
Unit Test test Suite
Prepare for testing early in the software development cycle
Early snapping to errors
It doesn't have to be proven, but I believe it's true.
Assertions are statements that are used in code
The validity of the test code at development time, such as the song language result is not true
Trigger Assertionerror
If the error is not captured the program will stop
Assertionerror
Assert if raise combination
Raise exception
Activating assertion variables __debug__ special variables
Python-o code optimization means that other optimizations are performed in addition to performing other optimization processing to delete assertions
Assertion tests make programs run slowly
Options
Optimize optimize
Optimize
Optimize
The deployer removes assertions that are considered to be development-phase features
Add Assertion Catch Error
Test case Run Environment testcase Tester Test Fixture
Create component Tag label tag
command button Cmdexit Coommand button Order button
Radio buttons radio button option button Check button
Radio button option button
Radio option button
Check button;
Layout graphical User interface
Customizing the widget appearance
Create a custom dialog box
Fill Order
Tkinter Creating GUI Widgets
Most GUI frameworks are based on a widget widget model widget that is a component of the GUI button label and text box widget
Some widgets are just used to accommodate other widgets and layout them to the screen
Table frame
The GUI is the layout of several small components
Myfirstgui Simple windows and labels
The simple explanation of the label is to write a sign on a piece of paper that indicates a certain kind of information;
Widget Label Creation Object
Do not complete any action
Script does not handle any GUI events
The bottom of the window and stretch it
Creating GUI widgets with Tkinter
Most GUI frameworks are based on widget Widgets widget model parts are GUI Widgets button label text box textbox
are widgets--most parts of the widget are graphically displayed on the screen.
Some widgets are just used to accommodate other widgets and layout them to the screen
The GUI is the layout of several small components
Tkinter writing a real-world GUI application
Simple window-label GUI
Import Tkinter
From Tkiner Import *
Widget = Label (None,text = ' This is my first gui!! ')
Widget.pack ()
Widget.mainloop ()
Import tkinter Module Import a label class from Tkinter
Import all classes from Tkinter create objects for each part-widget
Widget.pack the label L parent window to layout the part Abel to
Import Tkinter
From Tkinter Import *
Label (Text = ' My First gui! '). Pack (expand = Yes,fill = BOTH)
Label (Text = ' First gui! '). Pack (expand = Yes,fill = BOTH)
Mainloop ()
Create a label with text
Parent window Extension Widget also expands
Configure Part---widget options
Label assignment text configuration part options
Expand Fill = BOTH
Expand = YES extended fill;
Configuring component Parts
Create the same parent window label
Do not create their same settings option until they are created and then set;
Working with Widgets
How to create a basic label
How to format widgets
A successful program is not just a good appearance for practical operation
GUI add multi-parts
Part execution action
Use the program to react to various actions of the user
Create a label part
button
Import Sys
From Tkinter Import *
Widget = Button (none,text = ' Click Me ', command = sys.exit)
Widget.pack ()
Widget.mainloop ()
Changing the component type Add a second widget to the Options window outside of the exit program
Creating layouts
It is important to consider the hierarchy between the individual parts
Hierarchies are generally referred to as parent-child relationships
The previous example creates many parts
The module is imported
Functions and methods under the class in the Import module
Cleass mode
Def
tkinter-module. button-class. Pack-method;
Control Part appearance appearance
Façade
Aspect
Guise
Exterior
Controlling the appearance of parts
Form forms ActiveX Windows
Create visually appealing programs
Python GUI Preliminary