Оцените презентацию от 1 до 5 баллов!
Тип файла:
ppt / pptx (powerpoint)
Всего слайдов:
131 слайд
Для класса:
1,2,3,4,5,6,7,8,9,10,11
Размер файла:
605.76 kB
Просмотров:
89
Скачиваний:
1
Автор:
неизвестен
Слайды и текст к этой презентации:
№1 слайд![Python Vasiliy Kovalev MERA -](/documents_6/0beda689dc67b035828f91587d962c32/img0.jpg)
Содержание слайда: Python
Vasiliy Kovalev
MERA - 2019
№2 слайд![About Python](/documents_6/0beda689dc67b035828f91587d962c32/img1.jpg)
Содержание слайда: About Python
№3 слайд![What is Python? A programming](/documents_6/0beda689dc67b035828f91587d962c32/img2.jpg)
Содержание слайда: What is Python?
A programming language
Open Source
Free; source code available
Download on your own system
Written by Guido van Rossum
Monty Python’s Flying Circus…
№4 слайд![Features of Python A script](/documents_6/0beda689dc67b035828f91587d962c32/img3.jpg)
Содержание слайда: Features of Python
A script language
Interpreted
No compile/link stage
Write and run
Slow compared to C, C++
Elegant design; “tight”
Designed for
Quick-and-dirty scripts
Reusable modules
Very large systems
Object-oriented
Very well-designed
But you don’t have to use it
№5 слайд![The Zen of Python Beautiful](/documents_6/0beda689dc67b035828f91587d962c32/img4.jpg)
Содержание слайда: The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one — and preferably only one — obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than 'right now'.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!
№6 слайд![Part Variables and built-in](/documents_6/0beda689dc67b035828f91587d962c32/img5.jpg)
Содержание слайда: Part 1:
Variables and built-in types
№7 слайд![Basic data types](/documents_6/0beda689dc67b035828f91587d962c32/img6.jpg)
Содержание слайда: Basic data types
№8 слайд![Useful functions type object](/documents_6/0beda689dc67b035828f91587d962c32/img7.jpg)
Содержание слайда: Useful functions
type(object) – returns type of an object
dir(object) – returns a list of attributes for an object
№9 слайд![Useful functions help object](/documents_6/0beda689dc67b035828f91587d962c32/img8.jpg)
Содержание слайда: Useful functions
help(object) – returns description of an object
№10 слайд![Numeric types and literals](/documents_6/0beda689dc67b035828f91587d962c32/img9.jpg)
Содержание слайда: Numeric types and literals
№11 слайд![Numeric tools](/documents_6/0beda689dc67b035828f91587d962c32/img10.jpg)
Содержание слайда: Numeric tools
№12 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img11.jpg)
№13 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img12.jpg)
№14 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img13.jpg)
№15 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img14.jpg)
№16 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img15.jpg)
№17 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img16.jpg)
№18 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img17.jpg)
№19 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img18.jpg)
№20 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img19.jpg)
№21 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img20.jpg)
№22 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img21.jpg)
№23 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img22.jpg)
№24 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img23.jpg)
№25 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img24.jpg)
№26 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img25.jpg)
№27 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img26.jpg)
№28 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img27.jpg)
№29 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img28.jpg)
№30 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img29.jpg)
№31 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img30.jpg)
№32 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img31.jpg)
№33 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img32.jpg)
№34 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img33.jpg)
№35 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img34.jpg)
№36 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img35.jpg)
№37 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img36.jpg)
№38 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img37.jpg)
№39 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img38.jpg)
№40 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img39.jpg)
№41 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img40.jpg)
№42 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img41.jpg)
№43 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img42.jpg)
№44 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img43.jpg)
№45 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img44.jpg)
№46 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img45.jpg)
№47 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img46.jpg)
№48 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img47.jpg)
№49 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img48.jpg)
№50 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img49.jpg)
№51 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img50.jpg)
№52 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img51.jpg)
№53 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img52.jpg)
№54 слайд![](/documents_6/0beda689dc67b035828f91587d962c32/img53.jpg)
№55 слайд![Boolean expressions True and](/documents_6/0beda689dc67b035828f91587d962c32/img54.jpg)
Содержание слайда: Boolean expressions
‘True’ and ‘ False’ are predefined values; actually integers 1 and 0
Value 0 is considered False, all other values True
The usual Boolean expression operators: not, and, or
№56 слайд![String Single quotes or](/documents_6/0beda689dc67b035828f91587d962c32/img55.jpg)
Содержание слайда: String
Single quotes or double quotes can be used for string literals
Produces exactly the same value
Special characters in string literals: \n newline, \t tab, others
Triple quotes useful for large chunks of text in program code
№57 слайд![String conversions Convert](/documents_6/0beda689dc67b035828f91587d962c32/img56.jpg)
Содержание слайда: String conversions
Convert data types using functions ‘str’, ‘int’, ‘float’
‘repr’ is a variant of ‘str’
intended for strict, code-like representation of values
‘str’ usually gives nicer-looking representation
Function ‘eval’ interprets a string as a Python expression
№58 слайд![String operations Common](/documents_6/0beda689dc67b035828f91587d962c32/img57.jpg)
Содержание слайда: String operations
Common string operations on page 75 in ‘Learning Python’
№59 слайд![Changing strings. Not! A](/documents_6/0beda689dc67b035828f91587d962c32/img58.jpg)
Содержание слайда: Changing strings. Not!
A string cannot be changed in Python! Immutable
Good reasons for this; more later
Create new strings from bits and pieces of old
№60 слайд![String methods Strings have a](/documents_6/0beda689dc67b035828f91587d962c32/img59.jpg)
Содержание слайда: String methods
Strings have a set of built-in methods
No method ever changes the original string!
Several methods produce new strings
A list on page 91 in ‘Learning Python’
№61 слайд![List Ordered collection of](/documents_6/0beda689dc67b035828f91587d962c32/img60.jpg)
Содержание слайда: List
Ordered collection of objects; array
Heterogenous; may contain mix of objects of any type
№62 слайд![List operations Lists are](/documents_6/0beda689dc67b035828f91587d962c32/img61.jpg)
Содержание слайда: List operations
Lists are mutable; can be changed in-place
Lists are dynamic; size may be changed
№63 слайд![List methods, part Lists have](/documents_6/0beda689dc67b035828f91587d962c32/img62.jpg)
Содержание слайда: List methods, part 1
Lists have a set of built-in methods
Some methods change the list in-place
№64 слайд![List methods, part Use the](/documents_6/0beda689dc67b035828f91587d962c32/img63.jpg)
Содержание слайда: List methods, part 2
Use the built-in 'sort' method: efficient
The list is sorted in-place; a new list is not produced!
№65 слайд![Objects, names and references](/documents_6/0beda689dc67b035828f91587d962c32/img64.jpg)
Содержание слайда: Objects, names and references
All values are objects
A variable is a name referencing an object
An object may have several names referencing it
Important when modifying objects in-place!
You may have to make proper copies to get the effect you want
For immutable objects (numbers, strings), this is never a problem
№66 слайд![Dictionary An unordered](/documents_6/0beda689dc67b035828f91587d962c32/img65.jpg)
Содержание слайда: Dictionary
An unordered collection of key/value pairs
Each key maps to a value
Also called "mapping", "hash table" or "lookup table"
№67 слайд![Forgetting things garbage](/documents_6/0beda689dc67b035828f91587d962c32/img66.jpg)
Содержание слайда: Forgetting things: garbage collection
What happens to the object when its name is ’del’ed, or reassigned to another object?
Don’t worry, be happy!
The Python systems detects when an object is ’lost in space’
It keeps track of the number of references to it
The object’s memory gets reclaimed; garbage collection
A few problematic special cases; cyclical references
№68 слайд![Dictionary methods, part](/documents_6/0beda689dc67b035828f91587d962c32/img67.jpg)
Содержание слайда: Dictionary methods, part 1
№69 слайд![Dictionary methods, part](/documents_6/0beda689dc67b035828f91587d962c32/img68.jpg)
Содержание слайда: Dictionary methods, part 2
№70 слайд![Tuple Same as list, except](/documents_6/0beda689dc67b035828f91587d962c32/img69.jpg)
Содержание слайда: Tuple
Same as list, except immutable
Once created, can't be changed
Some functions return tuples
№71 слайд![String formatting Tuples are](/documents_6/0beda689dc67b035828f91587d962c32/img70.jpg)
Содержание слайда: String formatting
Tuples are used as operands in string formatting when >1 items
The length of the tuple must match the number of format codes in the string
Lists won't do!
№72 слайд![Part Statements](/documents_6/0beda689dc67b035828f91587d962c32/img71.jpg)
Содержание слайда: Part 2:
Statements
№73 слайд![if statement block structure](/documents_6/0beda689dc67b035828f91587d962c32/img72.jpg)
Содержание слайда: 'if' statement; block structure
The Python feature that one either loves or hates
Block structure is determined by indentation
Edit a new script file 't2.py'
In window 't1.py' do 'File', 'New Window', then 'Save As…
Use the 'if' statement:
№74 слайд![Dictionary often better than](/documents_6/0beda689dc67b035828f91587d962c32/img73.jpg)
Содержание слайда: Dictionary often better than if… elif…
Particularly with many hardcoded choices (elif's)…
More compact, and more efficient
This pattern is very useful
№75 слайд![Built-in types and their](/documents_6/0beda689dc67b035828f91587d962c32/img74.jpg)
Содержание слайда: Built-in types and their Boolean interpretations
№76 слайд![for statement Repetition of a](/documents_6/0beda689dc67b035828f91587d962c32/img75.jpg)
Содержание слайда: 'for' statement
Repetition of a block of statements
Iterate through a sequence (list, tuple, string, iterator)
№77 слайд![Built-in functions range and](/documents_6/0beda689dc67b035828f91587d962c32/img76.jpg)
Содержание слайда: Built-in functions 'range' and 'xrange'
Built-in functions 'range' and 'xrange' useful with 'for'
'range' creates a list
Warning: may use lots of memory; inefficient!
№78 слайд![while statement Repetition of](/documents_6/0beda689dc67b035828f91587d962c32/img77.jpg)
Содержание слайда: 'while' statement
Repetition of a block of statements
Loop until test becomes false, or 'break'
№79 слайд![Optional else block in loops](/documents_6/0beda689dc67b035828f91587d962c32/img78.jpg)
Содержание слайда: Optional 'else' block in loops
'else' block executed if no 'break' encountered
May often replace success/failure flags
Valid in 'for' and 'while' loops
№80 слайд![Error handling try and except](/documents_6/0beda689dc67b035828f91587d962c32/img79.jpg)
Содержание слайда: Error handling: ’try’ and ’except’
Run-time error normally causes execution to bomb
The error message gives type of error
Use a ’try’, ’except’ blocks to catch and handle errors
№81 слайд![How to split up long lines](/documents_6/0beda689dc67b035828f91587d962c32/img80.jpg)
Содержание слайда: How to split up long lines
Sometimes a source code line needs splitting up
Indentation rule means we do not have free-format!
№82 слайд![Statements not covered in](/documents_6/0beda689dc67b035828f91587d962c32/img81.jpg)
Содержание слайда: Statements not covered in this course
'finally': used with 'try', 'except'
'raise': causes an exception
'yield': in functions
'global': within functions
'exec': execute strings as code
There is no 'goto' statement!
№83 слайд![Part Functions](/documents_6/0beda689dc67b035828f91587d962c32/img82.jpg)
Содержание слайда: Part 3:
Functions
№84 слайд![How to define your own](/documents_6/0beda689dc67b035828f91587d962c32/img83.jpg)
Содержание слайда: How to define your own function
Use the 'def' statement
Function body follows; indented!
This is a statement like others
Can be placed basically anywhere
Required: Define the function before calling it
№85 слайд![Function features The value](/documents_6/0beda689dc67b035828f91587d962c32/img84.jpg)
Содержание слайда: Function features
The value of an argument is not checked for type
Often very useful; overloading without effort
Of course, the function may still bomb if invalid value is given
The documentation string is not required (more later)
But strongly encouraged!
Make a habit of writing one (before writing the function code)
A user-defined function has exactly the same status as a built-in function, or a function from another module
№86 слайд![Function arguments fixed](/documents_6/0beda689dc67b035828f91587d962c32/img85.jpg)
Содержание слайда: Function arguments: fixed
Fixed number of arguments
Associated by order
№87 слайд![Function arguments variable](/documents_6/0beda689dc67b035828f91587d962c32/img86.jpg)
Содержание слайда: Function arguments: variable
List of any number of arguments
Useful when unknown number of arguments needed
The argument values collected into a tuple
Called 'args', by convention
The ’*’ is the magical part
№88 слайд![Function arguments default](/documents_6/0beda689dc67b035828f91587d962c32/img87.jpg)
Содержание слайда: Function arguments: default values
Arguments may have default values
When argument not given in a call, default value is used
If no default value, and not given when called: bombs
Use explicit names to override argument order
№89 слайд![Function arguments keywords](/documents_6/0beda689dc67b035828f91587d962c32/img88.jpg)
Содержание слайда: Function arguments: keywords
Keyword/value arguments
The argument values collected into a dictionary
Called 'kwargs', by convention
The ’**’ is the magical part
First attempts to match existing argument names
№90 слайд![Function arguments local](/documents_6/0beda689dc67b035828f91587d962c32/img89.jpg)
Содержание слайда: Function arguments: local variables
Arguments become local variables
Immutable values are copied, in effect
Mutable values may still be changed: be careful
Variables created within 'def' block are local
Forgotten on return
№91 слайд![Function without return value](/documents_6/0beda689dc67b035828f91587d962c32/img90.jpg)
Содержание слайда: Function without 'return': value None
A function does not have to use the 'return' statement
If not, then same as a 'procedure' in other languages
Actually returns a value anyway: 'None'
A 'return' without value is OK: returns 'None'
'None' is a special value meaning 'nothing'
Useful in many contexts
Particularly in object-oriented programming (more later)
№92 слайд![The math module functions and](/documents_6/0beda689dc67b035828f91587d962c32/img91.jpg)
Содержание слайда: The 'math' module: functions and constants
A peek at modules
Math functions available in a separate module
№93 слайд![Functions are objects names](/documents_6/0beda689dc67b035828f91587d962c32/img92.jpg)
Содержание слайда: Functions are objects; names are references
A function is just another kind of object
Nothing magical about their names; can be changed
№94 слайд![Built-in function map](/documents_6/0beda689dc67b035828f91587d962c32/img93.jpg)
Содержание слайда: Built-in function 'map'
Built-in function that works on a list
'map' takes a function and a list
The function must take only one argument, and return one value
The function is applied to each value of the list
The resulting values are returned in a list
№95 слайд![Built-in function reduce](/documents_6/0beda689dc67b035828f91587d962c32/img94.jpg)
Содержание слайда: Built-in function 'reduce'
№96 слайд![Built-in function filter](/documents_6/0beda689dc67b035828f91587d962c32/img95.jpg)
Содержание слайда: Built-in function 'filter'
№97 слайд![Files reading A file object](/documents_6/0beda689dc67b035828f91587d962c32/img96.jpg)
Содержание слайда: Files: reading
A file object is created by the built-in function 'open'
The file object has a set of methods
The 'read' methods get data sequentially from the file
'read': Get the entire file (or N bytes) and return as a single string
'readline': Read a line (up to and including newline)
'readlines': Read all lines and return as a list of strings
№98 слайд![Files writing The write](/documents_6/0beda689dc67b035828f91587d962c32/img97.jpg)
Содержание слайда: Files: writing
The 'write' method simply outputs the given string
The string does not have to be ASCII; binary contents allowed
№99 слайд![Part Modules](/documents_6/0beda689dc67b035828f91587d962c32/img98.jpg)
Содержание слайда: Part 4:
Modules
№100 слайд![Example Reverse complement NT](/documents_6/0beda689dc67b035828f91587d962c32/img99.jpg)
Содержание слайда: Example: Reverse complement NT sequence
Given a nucleotide sequence, produce reverse complement
Use available features
№101 слайд![Make a module of the code How](/documents_6/0beda689dc67b035828f91587d962c32/img100.jpg)
Содержание слайда: Make a module of the code
How to make the code even more reusable?
Step 2: Make a module out of it
Is actually already a module!
Let’s simply rename it to ’ntseq.py’
№102 слайд![How to use the module import](/documents_6/0beda689dc67b035828f91587d962c32/img101.jpg)
Содержание слайда: How to use the module: ’import’ statement
The ’import’ statement makes a module available
The module name (not the file name) is imported: skip the ’.py’
Access module features through the ’dot’ notation
№103 слайд![Module self-test code the](/documents_6/0beda689dc67b035828f91587d962c32/img102.jpg)
Содержание слайда: Module self-test code: the ’__name__’ trick
The ’import’ statement executes all code in the module file
How to ’hide’ self-test code?
Use the predefined variable ’__name__’:
If executed as the main program: value ’__main__’
If executed as a module: some other value
№104 слайд![Now, the import statement](/documents_6/0beda689dc67b035828f91587d962c32/img103.jpg)
Содержание слайда: Now, the ’import’ statement behaves
№105 слайд![Modules are easy, fun, and](/documents_6/0beda689dc67b035828f91587d962c32/img104.jpg)
Содержание слайда: Modules are easy, fun, and powerful
The module feature is the basis for Python's ability to scale to really large software systems
Easy to create: every Python source code file is a module!
Features to make a module elegant:
Doc strings
'__name__' trick
Namespace concept
Be sure to browse the standard library modules!
You will find extremely useful stuff there
You will learn good coding habits
Packages are directories of several associated modules
Not covered in this course. A few minor interesting points
№106 слайд![Namespaces A namespace is a](/documents_6/0beda689dc67b035828f91587d962c32/img105.jpg)
Содержание слайда: Namespaces
A namespace is a bag of names
A module is a namespace
Use the built-in function ’dir’ to list the names in a namespace
’import’ statement modifies the namespace
№107 слайд![Avoiding clutter in your](/documents_6/0beda689dc67b035828f91587d962c32/img106.jpg)
Содержание слайда: Avoiding clutter in your namespace
Using ’from module import *’ can create clutter
Fine-tuning of import; bring in only selected things
Rename things from a module
Avoid name collisions
Make it clearer
№108 слайд![Doc strings doc We have](/documents_6/0beda689dc67b035828f91587d962c32/img107.jpg)
Содержание слайда: Doc strings: ’__doc__’
We have mentioned documentation strings before
The first string in a module
The first string after a ’def’ statement
Accessed through variable ’__doc__’
Feature to facilitate creation of documentation
Used by tools to produce documentation, such as ’pydoc’
See ’Module Docs’ in ’Start’ > ’Programs’ > ’Python 2.3’
№109 слайд![Part Object-oriented](/documents_6/0beda689dc67b035828f91587d962c32/img108.jpg)
Содержание слайда: Part 5:
Object-oriented programming, classes
№110 слайд![Classes vs. objects instances](/documents_6/0beda689dc67b035828f91587d962c32/img109.jpg)
Содержание слайда: Classes vs. objects (instances)
A class is like a
Prototype
Blue-print ("ritning")
An object creator
A class defines potential objects
What their structure will be
What they will be able to do
Objects are instances of a class
An object is a container of data: attributes
An object has associated functions: methods
№111 слайд![A class example Geometrical](/documents_6/0beda689dc67b035828f91587d962c32/img110.jpg)
Содержание слайда: A class example: Geometrical shapes
Let's define classes for geometrical shapes
With data; position, etc
With functions: compute area, etc
№112 слайд![Instances of classes Let s](/documents_6/0beda689dc67b035828f91587d962c32/img111.jpg)
Содержание слайда: Instances of classes
Let's create some instances of the Circle class
Look at attribute 'radius'
Use the method 'area'
№113 слайд![Changing an instance](/documents_6/0beda689dc67b035828f91587d962c32/img112.jpg)
Содержание слайда: Changing an instance: references
Variables may reference the same object
Changing an attribute changes the object, not the reference
№114 слайд![Changing an instance](/documents_6/0beda689dc67b035828f91587d962c32/img113.jpg)
Содержание слайда: Changing an instance: attribute add/delete
An attribute can be added!
And deleted!
№115 слайд![Equality between objects Two](/documents_6/0beda689dc67b035828f91587d962c32/img114.jpg)
Содержание слайда: Equality between objects
Two kinds of equality:
Are the two objects similar in value?
Are the two references actually pointing to the same object?
№116 слайд![Special methods in classes](/documents_6/0beda689dc67b035828f91587d962c32/img115.jpg)
Содержание слайда: Special methods in classes
Special methods '__xxx__' in classes
Define custom-made behaviour
See page 327 in 'Learning Python'
№117 слайд![Using the special methods,](/documents_6/0beda689dc67b035828f91587d962c32/img116.jpg)
Содержание слайда: Using the special methods, part 1
Special method definitions are detected by Python
Built-in functions use them; see documentation
№118 слайд![Using the special methods,](/documents_6/0beda689dc67b035828f91587d962c32/img117.jpg)
Содержание слайда: Using the special methods, part 2
Defining special methods may clarify code tremendously
But: Stay reasonable 'natural'!
№119 слайд![Inheritance Class hierarchies](/documents_6/0beda689dc67b035828f91587d962c32/img118.jpg)
Содержание слайда: Inheritance: Class hierarchies
Let's define a general 'Shape' class
'Circle' is a special case of 'Shape'
'Blob' is also a special case of 'Shape'
Notice: redefinition of 'is_round' in 'Blob'
№120 слайд![Instances of classes using](/documents_6/0beda689dc67b035828f91587d962c32/img119.jpg)
Содержание слайда: Instances of classes using inheritance
Which method is called by which instance?
Polymorphism
Selection of method depends on actual class of the instance
Extremely powerful, if properly designed class hierarchy
№121 слайд![Part Standard library modules](/documents_6/0beda689dc67b035828f91587d962c32/img120.jpg)
Содержание слайда: Part 6:
Standard library modules
№122 слайд![Module re , part Define a](/documents_6/0beda689dc67b035828f91587d962c32/img121.jpg)
Содержание слайда: Module 're', part 1
Define a pattern
The pattern syntax is very much like Perl or grep
Apply it to a string
Process the results
№123 слайд![Module sys , part sys.argv](/documents_6/0beda689dc67b035828f91587d962c32/img122.jpg)
Содержание слайда: Module 'sys', part 1
sys.argv
List of command-line arguments; sys.argv[0] is script name
sys.path
List of directory names, where modules are searched for
sys.platform
String to identify type of computer system
№124 слайд![Module sys , part sys.stdout,](/documents_6/0beda689dc67b035828f91587d962c32/img123.jpg)
Содержание слайда: Module 'sys', part 2
sys.stdout, sys.stdin, sys.stderr
Predefined file objects for input/output
'print' stuff goes to 'sys.stdout'
May be set to other files
sys.exit(n)
Force exit from Python execution
'n' is an integer error code, normally 0
№125 слайд![Module os , part os.getcwd](/documents_6/0beda689dc67b035828f91587d962c32/img124.jpg)
Содержание слайда: Module 'os', part 1
os.getcwd()
Returns the current directory
№126 слайд![Module os , part os.chdir](/documents_6/0beda689dc67b035828f91587d962c32/img125.jpg)
Содержание слайда: Module 'os', part 2
os.chdir(path)
Changes the current working directory to 'path'
os.listdir(path)
Return a list of the contents of the directory 'path'
os.mkdir(path)
Create the directory 'path'
os.rmdir(path)
Remove the directory 'path'
os.remove(path)
Remove the file named 'path'
№127 слайд![Module os , part os.system](/documents_6/0beda689dc67b035828f91587d962c32/img126.jpg)
Содержание слайда: Module 'os', part 3
os.system(command)
Execute the shell command (string) in a subprocess
Return the error code as integer
os.popen(command, mode='r')
Run the shell command (string)
Open a pipe to the command, return as a file object
Mode is either read, or write; not both
os.popen2, os.popen3, os.popen4
Variants of os.popen, with different file objects
os.getpid()
Return the process ID as integer
№128 слайд![Module os.path , part](/documents_6/0beda689dc67b035828f91587d962c32/img127.jpg)
Содержание слайда: Module 'os.path', part 1
os.path.abspath(path)
Returns the absolute path for the given relative 'path'
№129 слайд![Module os.path , part](/documents_6/0beda689dc67b035828f91587d962c32/img128.jpg)
Содержание слайда: Module 'os.path', part 2
os.path.join(path, path, …)
Joint together the path parts intelligently into a valid path name
№130 слайд![Module os.path , part](/documents_6/0beda689dc67b035828f91587d962c32/img129.jpg)
Содержание слайда: Module 'os.path', part 3
os.path.isfile(path)
Is 'path' the name of a file?
os.path.isdir(path)
Is 'path' the name of a directory?
№131 слайд![Some other useful modules](/documents_6/0beda689dc67b035828f91587d962c32/img130.jpg)
Содержание слайда: Some other useful modules