SlideShare a Scribd company logo
The Awesome
File handling, Exceptions, Standard libraries,
debugger, magic functions, lambda forms, assert,
decorators, memory management.
Part-5
Summary of Previous Parts
We are done with discussing the Data types in python, Basic Data structures,
their syntaxes and their usage, inputs, Iterators/generators, Operators, Control
flow, Branches etc.
In the last presentation we have covered, Modules, Functions, Class, Metaclass,
OOPs Concepts.
We will move forward with lot many things,
I hope you enjoy the show.
2
File Handling
3 different modes in file handling. ‘r’, ‘w’, ‘a’.
‘b’ is file handling mode for binary, that you can append with any type and
change at binary level.
Open has to be followed by close.
with open doesn’t need any close.
Be careful if file is opened in write mode it removes everything that is already
present.
3
Exceptions
Syntax
4
● One try can have multiple excepts.
● Try can have else which will get executed
when no exception occurs.
● finally can be used with try which will
always get executed irrespective of any
situation.
● We can manually raise exception if we
want.
Standard Libraries
There is a hell lot of standard libraries present in python.
Refer the link to read about all standard libraries.
https://docs.python.org/2/library/
5
Debugger & Magic Functions
Python debugger is a very useful and
important tool in development.
There are many functions present in
debugger.
set_trace is the main function to debug the
code flow.
6
Magic functions are special methods that
you can define to add "magic" to your
classes.
They're always surrounded by double
underscores (e.g. __init__ or __lt__).
They're also not as well documented as they
need to be.
All of the magic methods for Python appear
in the same section in the Python docs,
but they're scattered about and only
loosely organized.
Lambda
These functions are throw-away functions, i.e.
they are just needed where they have been
created.
Lambda functions are mainly used in
combination with the functions filter(), map()
and reduce().
The lambda feature was added to Python due to
the demand from Lisp programmers
7
An anonymous functions
Map, Reduce, Filter
Using map and data set can be mapped to
a function like below.
Syntax is
map(aFunction, aSequence)
8
Reduce is like map but it uses lambda to reduce
the data to a value instead of mapping.
assert
Assert is always True.
Any value other than True will break the assert.
9
Decorators
Decorators allow you to make simple
modifications to callable objects like functions,
methods, or classes. We shall deal with
functions for this tutorial.
10
Memory Management
Memory management in Python involves a private heap containing all Python objects and data
structures. Interpreter takes care of Python heap and that the programmer has no access to
it.
The allocation of heap space for Python objects is done by Python memory manager. The core
API of Python provides some tools for the programmer to code reliable and more robust
program.
Python also has a build-in garbage collector which recycles all the unused memory. When an
object is no longer referenced by the program, the heap space it occupies can be freed.
The garbage collector determines objects which are no longer referenced by the sprogram
frees the occupied memory and make it available to the heap space.
The gc module defines functions to enable /disable garbage collector:
11
ThanksStay Tuned for the next part. Enjoy !!
12

More Related Content

PPTX
The Awesome Python Class Part-4
PPTX
The Awesome Python Class Part-3
PPTX
The Awesome Python Class Part-2
PPTX
This presentation is a great introduction to both fundamental programming con...
PPTX
Python Session - 3
PDF
Python Interview Questions And Answers
PPTX
Python Session - 6
PPTX
Introduction to Python programming Language
The Awesome Python Class Part-4
The Awesome Python Class Part-3
The Awesome Python Class Part-2
This presentation is a great introduction to both fundamental programming con...
Python Session - 3
Python Interview Questions And Answers
Python Session - 6
Introduction to Python programming Language

What's hot (20)

PDF
Anton Kasyanov, Introduction to Python, Lecture2
DOCX
Python Interview Questions For Experienced
PDF
Python revision tour i
DOCX
Python interview questions and answers
PPTX
Python Session - 5
PPTX
Python second ppt
DOCX
Notes on c++
PDF
Python interview questions and answers
PDF
Python Advanced – Building on the foundation
DOCX
Python interview questions for experience
PPSX
Programming with Python
DOCX
Python Interview Questions For Freshers
PPTX
11 Unit 1 Chapter 02 Python Fundamentals
PPTX
Python Session - 4
PPTX
Programming in C sesion 2
PPTX
Introduction To Programming with Python-1
PPTX
Chapter 9 python fundamentals
PDF
Programming in C Session 1
PPTX
Python Session - 2
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Anton Kasyanov, Introduction to Python, Lecture2
Python Interview Questions For Experienced
Python revision tour i
Python interview questions and answers
Python Session - 5
Python second ppt
Notes on c++
Python interview questions and answers
Python Advanced – Building on the foundation
Python interview questions for experience
Programming with Python
Python Interview Questions For Freshers
11 Unit 1 Chapter 02 Python Fundamentals
Python Session - 4
Programming in C sesion 2
Introduction To Programming with Python-1
Chapter 9 python fundamentals
Programming in C Session 1
Python Session - 2
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ad

Viewers also liked (7)

PDF
8 grejer som storföretag kan lära av startups
PPTX
Grunt och gulp
PDF
I huvudet på en cloudarkitekt | cloudcache.io
PDF
ASAS 2013 - Agility and the essence of software architecture
PPTX
Getting started with ES6 : Future of javascript
PPTX
Support Vector Machine without tears
PDF
Linear regression without tears
8 grejer som storföretag kan lära av startups
Grunt och gulp
I huvudet på en cloudarkitekt | cloudcache.io
ASAS 2013 - Agility and the essence of software architecture
Getting started with ES6 : Future of javascript
Support Vector Machine without tears
Linear regression without tears
Ad

Similar to The Awesome Python Class Part-5 (20)

PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PDF
Python Course In Chandigarh
PPTX
Chapter - 5.pptx
PDF
First Steps in Python Programming
PPTX
Functions in python
PDF
python interview prep question , 52 questions
PPTX
3-Tut2_Interfacing_Sensors_RPioT.pptx good reference
PPTX
Introduction to Python
DOCX
Python interview questions
PPTX
Introduction to python
PPTX
Python programming
PPTX
Python Programming Basics for begginners
PPTX
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
PPTX
Presentation new
PDF
Python Viva Interview Questions PDF By ScholarHat
PDF
Python Distilled Developer s Library 1st Edition David Beazley
PDF
Introduction to python
PPTX
file handling in python using exception statement
PDF
Free Python Notes PDF - Python Crash Course
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Python Course In Chandigarh
Chapter - 5.pptx
First Steps in Python Programming
Functions in python
python interview prep question , 52 questions
3-Tut2_Interfacing_Sensors_RPioT.pptx good reference
Introduction to Python
Python interview questions
Introduction to python
Python programming
Python Programming Basics for begginners
2024-25 TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
Presentation new
Python Viva Interview Questions PDF By ScholarHat
Python Distilled Developer s Library 1st Edition David Beazley
Introduction to python
file handling in python using exception statement
Free Python Notes PDF - Python Crash Course

Recently uploaded (20)

PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Well-logging-methods_new................
PPTX
Construction Project Organization Group 2.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
PPT on Performance Review to get promotions
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
additive manufacturing of ss316l using mig welding
bas. eng. economics group 4 presentation 1.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Well-logging-methods_new................
Construction Project Organization Group 2.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
OOP with Java - Java Introduction (Basics)
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Foundation to blockchain - A guide to Blockchain Tech
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mechanical Engineering MATERIALS Selection
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPT on Performance Review to get promotions
CYBER-CRIMES AND SECURITY A guide to understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Lecture Notes Electrical Wiring System Components
additive manufacturing of ss316l using mig welding

The Awesome Python Class Part-5

  • 1. The Awesome File handling, Exceptions, Standard libraries, debugger, magic functions, lambda forms, assert, decorators, memory management. Part-5
  • 2. Summary of Previous Parts We are done with discussing the Data types in python, Basic Data structures, their syntaxes and their usage, inputs, Iterators/generators, Operators, Control flow, Branches etc. In the last presentation we have covered, Modules, Functions, Class, Metaclass, OOPs Concepts. We will move forward with lot many things, I hope you enjoy the show. 2
  • 3. File Handling 3 different modes in file handling. ‘r’, ‘w’, ‘a’. ‘b’ is file handling mode for binary, that you can append with any type and change at binary level. Open has to be followed by close. with open doesn’t need any close. Be careful if file is opened in write mode it removes everything that is already present. 3
  • 4. Exceptions Syntax 4 ● One try can have multiple excepts. ● Try can have else which will get executed when no exception occurs. ● finally can be used with try which will always get executed irrespective of any situation. ● We can manually raise exception if we want.
  • 5. Standard Libraries There is a hell lot of standard libraries present in python. Refer the link to read about all standard libraries. https://docs.python.org/2/library/ 5
  • 6. Debugger & Magic Functions Python debugger is a very useful and important tool in development. There are many functions present in debugger. set_trace is the main function to debug the code flow. 6 Magic functions are special methods that you can define to add "magic" to your classes. They're always surrounded by double underscores (e.g. __init__ or __lt__). They're also not as well documented as they need to be. All of the magic methods for Python appear in the same section in the Python docs, but they're scattered about and only loosely organized.
  • 7. Lambda These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). The lambda feature was added to Python due to the demand from Lisp programmers 7 An anonymous functions
  • 8. Map, Reduce, Filter Using map and data set can be mapped to a function like below. Syntax is map(aFunction, aSequence) 8 Reduce is like map but it uses lambda to reduce the data to a value instead of mapping.
  • 9. assert Assert is always True. Any value other than True will break the assert. 9
  • 10. Decorators Decorators allow you to make simple modifications to callable objects like functions, methods, or classes. We shall deal with functions for this tutorial. 10
  • 11. Memory Management Memory management in Python involves a private heap containing all Python objects and data structures. Interpreter takes care of Python heap and that the programmer has no access to it. The allocation of heap space for Python objects is done by Python memory manager. The core API of Python provides some tools for the programmer to code reliable and more robust program. Python also has a build-in garbage collector which recycles all the unused memory. When an object is no longer referenced by the program, the heap space it occupies can be freed. The garbage collector determines objects which are no longer referenced by the sprogram frees the occupied memory and make it available to the heap space. The gc module defines functions to enable /disable garbage collector: 11
  • 12. ThanksStay Tuned for the next part. Enjoy !! 12