Python for Advance: 3 Days with Python: Expert Python Program in 72 Hours

Python for Advance: 3 Days with Python: Expert Python Program in 72 Hours

Python for Advance: 3 Days with Python: Expert Python Program in 72 Hours
Автор: Snake Tony
Дата выхода: 2022
Издательство: Independent publishing
Количество страниц: 263
Размер файла: 1,0 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

About the Authors 1
He received Best Paper Award the 15th International Conference on Multimedia Information Technology and Applications (MITA 2019) 1
Table of Contents 2
Chapter 1: Python File Handling 2
1. Opening and Closing Files in Python 2
What is File Handling in Python? 2
Why file handling? 2
Opening and Closing a File in Python 2
open() Function: 2
Example of Opening and Closing Files in Python 3
close() function: 3
Example with with statement: 3
Explanation 4
2. How to Read a File in Python 5
Introduction 5
File Access Modes 5
Reading a File in Python 6
Opening a File in Python 6
Usage: 6
Closing a File in Python 7
Usage: 7
1. The read() method in python: 7
2. The readline() method in python: 8
Usage: 8
3. The readlines() method in python: 9
Usage: 9
Reading a Binary File in Python 9
Example: 9
Reading Using the with open() Method in Python 10
Syntax: 10
3. How to Write a File in Python 10
Writing to a text file in Python 10
1. The write() function in Python: 10
Output 11
2. The writelines() function in Python: 12
Writing to a binary file in Python 12
Example 12
4. How to Delete File in Python? 12
Introduction 12
How to Delete Files Using Python? 13
1. Using the os module in python 13
2. Using the shutil module in python: 13
3. Using the Pathlib Module in Python 14
5. With Statement in Python 15
What is “with” Statement in Python 15
Wait… What is a buffer? 15
Try…Finally in Python 15
With in Python 15
But how does “with” know to close a file? 16
Using “with” in user-defined objects 16
Wait… Why would I use “with” in my custom function? 16
Output: 17
Contextlib Library 18
Output: 18
Chapter 2: Python Exception Handling 18
1. Exception Handling in Python 18
Introduction 18
What is Exception Handling in Python? 19
Common Exceptions in Python 20
Catching Specific Exceptions in Python 21
Raising Custom Exceptions 22
Syntax to Raise an Exception 22
try except and ELSE! 23
Syntax With Else Clause 23
Try Clause with Finally 24
Why Use Finally or Else in try..except? 26
What Happens if Errors are Raised in Except or Finally Block? 26
2. Assert Keyword in Python 27
Introduction to Assert in Python 27
What is Assert? 28
Why Use Assert in Python? 28
Python Assert Statement 28
What Does the Assertion Error do to our Code? 30
Where is Assertion used in Python? 31
1. Checking parameter types / classes / values 31
2. Checking “can’t happen” situations 31
3. Documentation of Understanding 32
Another Example of Assertion in Python 32
Chapter 3: Python Object & Class 33
1. Python Object Oriented Programming 33
Object Oriented Programming 33
Class 34
Object 34
Example 1: Creating Class and Object in Python 35
Methods 36
Example 2 : Creating Methods in Python 36
Inheritance 37
Example 3: Use of Inheritance in Python 37
Encapsulation 38
Example 4: Data Encapsulation in Python 38
Polymorphism 39
Example 5: Using Polymorphism in Python 40
2. Python Objects and Classes 41
Python Objects and Classes 41
Defining a Class in Python 41
Creating an Object in Python 43
Constructors in Python 44
Deleting Attributes and Objects 46
3. Python Inheritance 47
Inheritance in Python 47
Python Inheritance Syntax 47
Example of Inheritance in Python 48
Method Overriding in Python 50
4. Python Multiple Inheritance 51
Python Multiple Inheritance 51
Example 51
Python Multilevel Inheritance 52
Method Resolution Order in Python 52
5. Python Operator Overloading 54
Python Operator Overloading 54
Python Special Functions 55
Overloading the + Operator 57
Overloading Comparison Operators 60
Chapter 4: Python Advance Constructs 62
1. Python Modules 62
What are Modules in Python? 62
Formal Definition of Python Module 62
Features of Python Module 62
Types of Python Modules 63
InBuilt Module: 63
How to call a Built-In module?** 63
Variables in Module 64
The Import Statement 65
What is an Import Statement? 65
How to Use Import Modules 65
Using from <module_name> import statement 66
Python Module Search Path 67
Naming a Module 67
Re-Naming a Module 68
Reloading a Module 68
The dir() built-in Function 68
2. Packages in Python and Import Statement 69
Introduction 69
Importing Module From a Package in Python 69
Syntax: 70
Installing a Python Package Globally 70
Import Statement in Python 71
Output: 72
Example: 72
Output: 72
Importing Attributes Using the from Import Statement in Python 72
Syntax: 72
Output: 72
Output: 73
Importing Modules Using the From Import * Statement in Python 73
Syntax: 73
Example: 73
Output: 73
Importing Modules in Python Using the Import as Statement 73
Syntax: 73
Example: 73
Output: 74
Importing Class/Functions from Module in Python 74
Output: 74
Import User-defined Module in Python 74
Output: 74
Importing from Another Directory in Python 75
Output: 76
Importing Class from Another File in Python 76
Output: 77
3. Python Collection Module 77
Introduction to Modules 77
Collection Module 78
namedtuple() 78
OrderedDict() 80
defaultdict() 82
Counter() 84
deque() 85
Chainmap 87
4. Regular Expression in Python 89
RegEx Module 90
Python RegEx Expressions Functions 90
Meta Characters 90
Special Sequences in Python RegEx 91
Examples for each sequence are given below 91
Sets 92
findall(pattern, string) 93
search(pattern, string) 93
split(pattern, string) 94
sub(pattern, repl, string) 94
Match Object 94
5. Python Datetime 96
Introduction to Python Datetime 96
How to Use Date and Datetime Class? 97
Classes of DateTime Python Module 98
Date 98
Time 99
Points to Remember About Time Class 99
Datetime 100
Timedelta 101
Tzinfo 102
Naive & Aware Datetime Objects 102
Timezone 103
Basics of pytz Library 103
Date Class 104
.date() 104
.today() 105
.min 105
.max 105
.day 106
.month 106
.year 106
strftime() 107
Current Date 108
.today() 108
.now() 108
Use of datetime.strptime() 109
How to Get Current timeStamp? 109
How to Know the Day of the Given Date? 110
Generate a List of Dates from a Given Date 111
Algorithm 111
Applications Of Python DateTime Module 112
Chapter 5: Python Advanced Topics 113
1. Python Iterators 113
Iterators in Python 113
Iterating Through an Iterator 113
Working of for loop for Iterators 115
Building Custom Iterators 116
Python Infinite Iterators 117
2. Python Generators 119
Generators in Python 119
Create Generators in Python 120
Differences between Generator function and Normal function 120
Python Generators with a Loop 123
Python Generator Expression 124
Use of Python Generators 126
1. Easy to Implement 126
2. Memory Efficient 127
3. Represent Infinite Stream 127
4. Pipelining Generators 127
3. Python Closures 128
Nonlocal variable in a nested function 128
Defining a Closure Function 129
When do we have closures? 131
When to use closures? 131
3. Python Decorators 133
Decorators in Python 133
Prerequisites for learning decorators 133
Getting back to Decorators 136
Decorating Functions with Parameters 137
Chaining Decorators in Python 139
4. Python @property decorator 141
Class Without Getters and Setters 142
Using Getters and Setters 143
The property Class 146
The @property Decorator 149
5. Python Regular Expressions 151
Python RegEx 151
re.findall() 152
Example 1: re.findall() 152
re.split() 152
Example 2: re.split() 152
re.sub() 153
Example 3: re.sub() 153
re.subn() 154
Example 4: re.subn() 155
re.search() 155
Example 5: re.search() 155
Match object 156
match.group() 156
Example 6: Match object 156
match.start(), match.end() and match.span() 157
match.re and match.string 158
Using r prefix before RegEx 158
Example 7: Raw string using r prefix 158
Chapter 6: Error Handling 159
1. Python Error and In-built Exception in Python 159
Python: Syntax Error 159
Python: What is an Exception? 160
Decoding the Exception Message in Python 161
2. Python Exception Handling 161
Handling Exceptions using try and except 162
The try block 163
The except block 163
Code Execution continues after except block 163
Catching Multiple Exceptions in Python 164
Multiple except blocks 165
Handling Multiple Exceptions with on except block 165
Generic except block to Handle unknown Exceptions 166
3. Exeption Handling: Finally 167
finally block with/without Exception Handling 167
Exception in except block 168
4. Python Exception Handling: raise Keyword 169
raise Without Specifying Exception Class 171
raise With an Argument 172
Chapter 7: Multithreading 172
1. Introduction to Multithreading In Python 172
Threads 172
Types Of Thread 173
What is Multithreading? 173
Time for an Example 173
Multithreading in Python 174
2. Threading Module In Python 175
threading Module Functions 175
threading.active_count() Function 175
threading.current_thread() 176
threading.get_ident() 178
threading.enumerate() 178
threading.main_thread() 178
threading.settrace(fun) 179
threading.setprofile(fun) 179
threading.stack_size([size]) 179
threading.TIMEOUT_MAX 180
threading Module Objects 180
3. Thread class and its Object - Python Multithreading 180
How Thread works? 181
Functions and Constructor in the Thread class 181
Thread class Constructor 182
start() method 182
run() method 182
join([timeout]) method 183
getName() method 183
setName(name) method 183
isAlive() method 183
isDaemon() method 183
setDaemon(daemonic) method 183
4. Thread Synchronization using Event Object 184
Python Multithreading: Event Object 184
Initialize Event object 184
isSet() method 185
set() method 185
clear() method 185
wait([timeout]) method 185
Time for an Example 186
5. Timer Object - Python Multithreading 186
Syntax for creating Timer object 187
Methods of Timer class 187
start() method 187
cancel() method 187
Time for an Example 187
6. Condition Object - Thread Synchronization in Python 188
Condition object: wait(), notify() and notifyAll() 189
Condition class methods 189
acquire(*args) method 189
release() method 189
wait([timeout]) method 189
notify() method 190
notifyAll() method 190
Time for an Example! 190
7. Barrier Object - Python Multithreading 190
Functions provided by Barrier class 191
wait(timeout=None) method 191
reset() method 192
abort() method 192
parties 192
n_waiting 192
broken 193
Time for an Example! 193
Chapter 8: Python Logging 193
1. Python Logging Basic Configurations 193
Let's take an Example 194
Points to remember: 194
Store Logs in File 194
Set Format of Logs 195
Add process ID to logs with loglevel and message 195
Add Timestamp to logs with log message 195
Use the datefmt attribute 196
2. Python - Print Logs in a File 197
Python Logging - Store Logs in a File 197
3. Python Logging Variable Data 199
Example 199
There is Another way 200
4. Python Logging Classes and Functions 200
1. Logger class 201
2. LogRecord 201
3. Handler 201
4. Formatter 201
Several Logger objects 201
Chapter 9: Python With MySQL 203
1. MySQL with Python 203
Python MySQL - Prerequisites 203
What is MySQL? 204
MySQL Connector 204
Test the MySQL Connector 205
Creating the Connection 205
2. Python MySQL - Create Database 206
Python MySQL - CREATE DATABASE 206
Python MySQL - Create Database Example 206
Python MySQL - List all Database 207
3. Python MySQL - Create and List Table 209
Python MySQL - Create Table 209
SQL Query to Create Table 210
List existing Tables in a Database 211
Python MySQL - Table with Primary Key 212
What is Primary Key? 212
Add Primary Key during Table creation 213
Python MySQL - Describe the Table 214
Add Primary Key to Existing Table 215
4. Python MySQL - Insert data in Table 216
Python MySQL - INSERT Data 216
Inserting Single Row in MySQL Table 217
Inserting Multiple Rows in MySQL Table 218
5. Python MySQL - Select data from Table 220
Python MySQL - SELECT Data 220
Retrieve All records from MySQL Table 220
Retrieve data from specific Column(s) of a Table 222
Selecting Multiple columns from a Table 223
To fetch the first record - fetchone() 225
6. Python MySQL - Update Table data 226
Python MySQL UPDATE: Syntax 226
Python MySQL UPDATE Table Data: Example 226
7. Python MySQL - Delete Table Data 229
Python MySQL DELETE: Syntax 229
Python MySQL DELETE Table Data: Example 229
8. Python MySQL - Drop Table 232
Python MySQL DROP TABLE: Example 232
Python MySQL - Drop Table if it exists 233
9. Python MySQL - WHERE Clause 235
Python MySQL WHERE Clause 235
Using WHERE Clause 235
10. Python MySQL - Orderby Clause 237
Python MySQL ORDER BY Example 237
Python MySQL ORDER BY DESC 239
11. Python MySQL - Limit Clause 241
Python MySQL LIMIT: Example 242
Using OFFSET Keyword with LIMIT clause 243
12. Python MySQL - Table Joins 244
Python MySQL - Joining two tables 245
Python MySQL - Left Join 247
Python MySQL - Right Join 249
Conclusion 251

This book includes almost everything you need to get started as a python teacher. It includes topics:

  • Working with files
  • Exception handling
  • Object and class
  • Advanced designs
  • Iterators, generators, closures, decorators
  • Error handling
  • Multithreading
  • Logging
  • Mysql with python

Похожее:

Список отзывов:

Нет отзывов к книге.