SlideShare a Scribd company logo
Introduction to 
Programming with 
Python – Class 5 
SYED FARJAD ZIA ZAIDI
Class Objectives 
Class Objective 
Understanding Python Modules, File I/O & Exceptions
Class Material 
•Chapter 7 - Python 
for Informatics: 
Exploring 
Information 
Reading
Python Modules 
 Definition: 
A module is a file containing Python definitions and 
statements. The file name is the module name with the 
suffix .py appended.
Import Statement 
 You can use any Python source file as a module by executing an import 
statement in some other Python source file. The import has the following 
syntax: 
import module1[, module2[,... moduleN]
Python Files I/O 
Until now, you have been reading and writing to the standard input and 
output. Now, we will see how to play with actual data files. 
Python provides basic functions and methods necessary to manipulate files 
by default. You can do your most of the file manipulation using a file object.
The open() Function 
Before you can read or write a file, you have to open it using Python's built-in 
open() function. This function creates a file object, which would be utilized 
to call other support methods associated with it. 
 Syntax: 
file object = open(file_name [, access_mode][, buffering])
File attributes 
Attribute Description 
file.closed Returns true if file is closed, false 
otherwise. 
file.mode Returns access mode with which file was 
opened. 
file.name Returns name of the file. 
file.softspace Returns false if space explicitly required 
with print, true otherwise.
The close() Method: 
 The close() method closes the file, and then no more operations on that file 
object can be performed.
The read() & write() method 
read() write() 
The read() method reads a string from an 
open file. 
The write() method writes any string to an 
open file. 
fileObject.read([count]); fileObject.write(string);
Exceptions 
 In general, when a Python script encounters a situation that it can't cope 
with, it raises an exception. An exception is a Python object that represents 
an error. 
 When a Python script raises an exception, it must either handle the 
exception immediately otherwise it would terminate and come out.
Handling exception 
 If you have some suspicious code that may raise an exception, you can 
defend your program by placing the suspicious code in a try: block. After 
the try: block, include an except: statement, followed by a block of code 
which handles the problem as elegantly as possible.
Syntax for handling exceptions 
try: 
You do your operations here; 
...................... 
except ExceptionI: 
If there is ExceptionI, then execute this block. 
except ExceptionII: 
If there is ExceptionII, then execute this block. 
...................... 
else: 
If there is no exception then execute this block.
Assignment 
 Link to Facebook Group: 
https://www.facebook.com/groups/introtopython.iccbs/

More Related Content

What's hot (19)

Datastrucure
DatastrucureDatastrucure
Datastrucure
Mohamed Essam
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
Hamid Ghorbani
 
Java
JavaJava
Java
Dhruv Sabalpara
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
kanchanmahajan23
 
Python-classes-in-mumbai
Python-classes-in-mumbaiPython-classes-in-mumbai
Python-classes-in-mumbai
Vibrant Technologies & Computers
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
Hiranya Jayathilaka
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
CIB Egypt
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
BG Java EE Course
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
Techglyphs
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
MaheshPandit16
 
Filehandling
FilehandlingFilehandling
Filehandling
Muhammad Fahad
 
data file handling
data file handlingdata file handling
data file handling
krishna partiwala
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
Narendra Sisodiya
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3
Nick Efford
 
Data file handling
Data file handlingData file handling
Data file handling
Prof. Dr. K. Adisesha
 
Python basics
Python basicsPython basics
Python basics
Jyoti shukla
 

Viewers also liked (20)

Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
Syed Farjad Zia Zaidi
 
Logic: Language and Information 1
Logic: Language and Information 1Logic: Language and Information 1
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Emerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 ClassroomEmerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 Classroom
Syed Farjad Zia Zaidi
 
Internet History, Technology, and Security
Internet History, Technology, and SecurityInternet History, Technology, and Security
Internet History, Technology, and Security
Syed Farjad Zia Zaidi
 
Introduction to Computing with Java
Introduction to Computing with JavaIntroduction to Computing with Java
Introduction to Computing with Java
Syed Farjad Zia Zaidi
 
Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014
Syed Farjad Zia Zaidi
 
Foundations of Virtual Instruction
Foundations of Virtual InstructionFoundations of Virtual Instruction
Foundations of Virtual Instruction
Syed Farjad Zia Zaidi
 
Vision & sight
Vision & sightVision & sight
Vision & sight
Syed Farjad Zia Zaidi
 
Substituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scriptsSubstituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
Logic Over Language
Logic Over LanguageLogic Over Language
Logic Over Language
Purple, Rock, Scissors
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Python and HDF5: Overview
Python and HDF5: OverviewPython and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBIIntroduction to UBI
Introduction to UBI
Roy Lee
 
Python 4 Arc
Python 4 ArcPython 4 Arc
Python 4 Arc
absvis
 
The Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5PyThe Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
Clase 2 estatica
Clase 2 estatica Clase 2 estatica
Clase 2 estatica
Gerald Moreira Ramírez
 
Using HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py moduleUsing HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py module
The HDF-EOS Tools and Information Center
 
HDF5 Tools
HDF5 ToolsHDF5 Tools
HDF5 Tools
The HDF-EOS Tools and Information Center
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Emerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 ClassroomEmerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 Classroom
Syed Farjad Zia Zaidi
 
Internet History, Technology, and Security
Internet History, Technology, and SecurityInternet History, Technology, and Security
Internet History, Technology, and Security
Syed Farjad Zia Zaidi
 
Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Python and HDF5: Overview
Python and HDF5: OverviewPython and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBIIntroduction to UBI
Introduction to UBI
Roy Lee
 
Python 4 Arc
Python 4 ArcPython 4 Arc
Python 4 Arc
absvis
 
Ad

Similar to Introduction To Programming with Python-5 (20)

Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
MikialeTesfamariam
 
Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
Karudaiyar Ganapathy
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
Kongunadu College of Engineering and Technology
 
UNIT 5 PY.pptx - FILE HANDLING CONCEPTS
UNIT 5 PY.pptx   -  FILE HANDLING CONCEPTSUNIT 5 PY.pptx   -  FILE HANDLING CONCEPTS
UNIT 5 PY.pptx - FILE HANDLING CONCEPTS
drkangurajuphd
 
Master of computer application python programming unit 3.pdf
Master of computer application python programming unit 3.pdfMaster of computer application python programming unit 3.pdf
Master of computer application python programming unit 3.pdf
Krrai1
 
chapter 2(IO and stream)/chapter 2, IO and stream
chapter 2(IO and stream)/chapter 2, IO and streamchapter 2(IO and stream)/chapter 2, IO and stream
chapter 2(IO and stream)/chapter 2, IO and stream
amarehope21
 
Python files creation read,write Unit 5.pptx
Python files creation read,write Unit 5.pptxPython files creation read,write Unit 5.pptx
Python files creation read,write Unit 5.pptx
shakthi10
 
Python-files
Python-filesPython-files
Python-files
Krishna Nanda
 
Module2-Files.pdf
Module2-Files.pdfModule2-Files.pdf
Module2-Files.pdf
4HG19EC010HARSHITHAH
 
file handlling in python 23.12.24 geetha.pptx
file handlling  in python 23.12.24 geetha.pptxfile handlling  in python 23.12.24 geetha.pptx
file handlling in python 23.12.24 geetha.pptx
vlkumashankardeekshi th
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
File Handling as 08032021 (1).ppt
File Handling as 08032021 (1).pptFile Handling as 08032021 (1).ppt
File Handling as 08032021 (1).ppt
Raja Ram Dutta
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
Dozie Agbo
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
dickonsondorris
 
File Handling in Python -binary files.pptx
File Handling in Python -binary files.pptxFile Handling in Python -binary files.pptx
File Handling in Python -binary files.pptx
deepa63690
 
Python file handlings
Python file handlingsPython file handlings
Python file handlings
22261A1201ABDULMUQTA
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15
Vishal Dutt
 
UNIT 5 PY.pptx - FILE HANDLING CONCEPTS
UNIT 5 PY.pptx   -  FILE HANDLING CONCEPTSUNIT 5 PY.pptx   -  FILE HANDLING CONCEPTS
UNIT 5 PY.pptx - FILE HANDLING CONCEPTS
drkangurajuphd
 
Master of computer application python programming unit 3.pdf
Master of computer application python programming unit 3.pdfMaster of computer application python programming unit 3.pdf
Master of computer application python programming unit 3.pdf
Krrai1
 
chapter 2(IO and stream)/chapter 2, IO and stream
chapter 2(IO and stream)/chapter 2, IO and streamchapter 2(IO and stream)/chapter 2, IO and stream
chapter 2(IO and stream)/chapter 2, IO and stream
amarehope21
 
Python files creation read,write Unit 5.pptx
Python files creation read,write Unit 5.pptxPython files creation read,write Unit 5.pptx
Python files creation read,write Unit 5.pptx
shakthi10
 
file handlling in python 23.12.24 geetha.pptx
file handlling  in python 23.12.24 geetha.pptxfile handlling  in python 23.12.24 geetha.pptx
file handlling in python 23.12.24 geetha.pptx
vlkumashankardeekshi th
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
File Handling as 08032021 (1).ppt
File Handling as 08032021 (1).pptFile Handling as 08032021 (1).ppt
File Handling as 08032021 (1).ppt
Raja Ram Dutta
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
Dozie Agbo
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
dickonsondorris
 
File Handling in Python -binary files.pptx
File Handling in Python -binary files.pptxFile Handling in Python -binary files.pptx
File Handling in Python -binary files.pptx
deepa63690
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15
Vishal Dutt
 
Ad

More from Syed Farjad Zia Zaidi (19)

Web Application Architectures
Web Application ArchitecturesWeb Application Architectures
Web Application Architectures
Syed Farjad Zia Zaidi
 
Programming for Everybody (Python)
Programming for Everybody (Python)Programming for Everybody (Python)
Programming for Everybody (Python)
Syed Farjad Zia Zaidi
 
Learn to Program: The Fundamentals
Learn to Program: The FundamentalsLearn to Program: The Fundamentals
Learn to Program: The Fundamentals
Syed Farjad Zia Zaidi
 
Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014
Syed Farjad Zia Zaidi
 
Human-Computer Interaction
Human-Computer InteractionHuman-Computer Interaction
Human-Computer Interaction
Syed Farjad Zia Zaidi
 
Beginning Game Programming with C#
Beginning Game Programming with C#Beginning Game Programming with C#
Beginning Game Programming with C#
Syed Farjad Zia Zaidi
 
Computer Science 101
Computer Science 101Computer Science 101
Computer Science 101
Syed Farjad Zia Zaidi
 
Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
MindMuscle Xtreme
MindMuscle XtremeMindMuscle Xtreme
MindMuscle Xtreme
Syed Farjad Zia Zaidi
 
How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...
Syed Farjad Zia Zaidi
 
Level 1 DFD
Level 1 DFDLevel 1 DFD
Level 1 DFD
Syed Farjad Zia Zaidi
 
Context Level DFD
Context Level DFDContext Level DFD
Context Level DFD
Syed Farjad Zia Zaidi
 
Level 2 DFD
Level 2 DFDLevel 2 DFD
Level 2 DFD
Syed Farjad Zia Zaidi
 
Virtual education, and Future of Virtual education in Pakistan.
Virtual education, and Future of Virtual education in Pakistan.Virtual education, and Future of Virtual education in Pakistan.
Virtual education, and Future of Virtual education in Pakistan.
Syed Farjad Zia Zaidi
 
Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014
Syed Farjad Zia Zaidi
 
Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...
Syed Farjad Zia Zaidi
 
Virtual education, and Future of Virtual education in Pakistan.
Virtual education, and Future of Virtual education in Pakistan.Virtual education, and Future of Virtual education in Pakistan.
Virtual education, and Future of Virtual education in Pakistan.
Syed Farjad Zia Zaidi
 

Recently uploaded (20)

Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 

Introduction To Programming with Python-5

  • 1. Introduction to Programming with Python – Class 5 SYED FARJAD ZIA ZAIDI
  • 2. Class Objectives Class Objective Understanding Python Modules, File I/O & Exceptions
  • 3. Class Material •Chapter 7 - Python for Informatics: Exploring Information Reading
  • 4. Python Modules  Definition: A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
  • 5. Import Statement  You can use any Python source file as a module by executing an import statement in some other Python source file. The import has the following syntax: import module1[, module2[,... moduleN]
  • 6. Python Files I/O Until now, you have been reading and writing to the standard input and output. Now, we will see how to play with actual data files. Python provides basic functions and methods necessary to manipulate files by default. You can do your most of the file manipulation using a file object.
  • 7. The open() Function Before you can read or write a file, you have to open it using Python's built-in open() function. This function creates a file object, which would be utilized to call other support methods associated with it.  Syntax: file object = open(file_name [, access_mode][, buffering])
  • 8. File attributes Attribute Description file.closed Returns true if file is closed, false otherwise. file.mode Returns access mode with which file was opened. file.name Returns name of the file. file.softspace Returns false if space explicitly required with print, true otherwise.
  • 9. The close() Method:  The close() method closes the file, and then no more operations on that file object can be performed.
  • 10. The read() & write() method read() write() The read() method reads a string from an open file. The write() method writes any string to an open file. fileObject.read([count]); fileObject.write(string);
  • 11. Exceptions  In general, when a Python script encounters a situation that it can't cope with, it raises an exception. An exception is a Python object that represents an error.  When a Python script raises an exception, it must either handle the exception immediately otherwise it would terminate and come out.
  • 12. Handling exception  If you have some suspicious code that may raise an exception, you can defend your program by placing the suspicious code in a try: block. After the try: block, include an except: statement, followed by a block of code which handles the problem as elegantly as possible.
  • 13. Syntax for handling exceptions try: You do your operations here; ...................... except ExceptionI: If there is ExceptionI, then execute this block. except ExceptionII: If there is ExceptionII, then execute this block. ...................... else: If there is no exception then execute this block.
  • 14. Assignment  Link to Facebook Group: https://www.facebook.com/groups/introtopython.iccbs/