SlideShare a Scribd company logo
CBSE
CLASS 12
Ch-5 File Handling
SasikalaJayaprakash
INTRODUTION
 A file in itself is bunch of byes stored on some
storage device like hard –drive etc .
 Files help in storing information permanently .
TEXT FILES
• A text file store information in ASC11 or unicode characters
• line of text is terminated,(delimited )with a special character
known EOL (end of line)
• Default mode
• Extn of text file is .txt
• Translation occur
Access Modes
Opening position of file pointer
File modes Opening position of file pointer
r , rb , r+ , rb+ , r+b Beginning of file
W, wb, w+, wb+, w+b Beginning of file
a+, ab , a+ , ab+, a+b End of file if file exist otherwise
beginning of file
Opening files
<file _object name> =open (<file name >)
<file_ object name> =open(<file name >,<mode>)
with open <file_name > as <file_object
with open (‘a.txt’ , ‘r’ ) as myfile
myfile = open (‘a.txt’, ‘ r’ )
READING FILES
METHOD SYNTAX DESCRIPTION
Read() <filehandle>. read([n]) Read at most n bytes; if no n is
specified , reads the entire file ,
return form of string
Readline() <filehandle>.readline([n]) Reads a line of input , if n is
specified reads at most n bytes,
returns in form of string
Readlines() <filehandle> . readlines() Read all lines and return in a list
Writing onto files
Method Syntax Description
write () <file handle>.write(str1) writes string str1 to file
referenced by <file
handle>
writelines() <file
handle>.writeline(L)
write all strings in list L as
lines to file referenced by
<filehandle>
Standard Input ,Output and error stream
• Standard input device( stdin ) – reads from the
keyboard
• Standard output device (stdout) – prints to the
display and can redirected as standard input
• Standard error device(stderr) – same as stdout but
normally only for errors
Binary files
 A binary file is just a file a that contain information in the
same format in which the information is held in memory
 There is no delimiter for a line
 No translations occur required in binary files
 Faster and easier for a program to read and write
 Extn is .dat file
Pickling and unpickling
• pickling refers to the process of converting the
structure(such as list or dict ) to a byte stream before
writing to the file .
Structure(list or
dictionary)
Pickling Byte stream
pickle.dump ()
Used to write object into file
syntax : pickle.dump(<structure>,fileobject)
file object is the file handle of the file where you write
the contents
pickle.load()
• used to read data from file
• syntax : structure=pickle.load(fileobject)
Load()
import pickle
def read():
f1=open('s2.dat','rb')
try:
while True:
rec=pickle.load(f1)
print(rec)
except EOFError:
f1.close()
read()
Dump()
import pickle
def write():
f1=open('s2.dat','wb')
rec=[ ]
while True
mark1,mark2,mark3=0,0,0
r=int(input("enter rollno:"))
n=input("enter name:")
m1=int(input("enter mark1:"))
m2=int(input("enter mark2:"))
m3=int(input("enter mark3:"))
a=(m1+m2+m3)/3
lst=[r,n,m1,m2,m3,a]
rec.append(lst)
pickle.dump(rec,f1)
f1.close()
write()
CSV Files
• CSV files are comma seperated values , each line
of the file is data record .Each record consist of
one or more fields seperated by commas .Data
stores in the form of rows and columns
• It is a text file
• It is mainly useful in importing and exporting
excel files into csv files and processing in python
• File object , csv object to be created
• Accessing is fast
• Can store large amount of data
• Extn is .csv
Reader () - read from the file
Syntax
csv.reader (file , delimiter)
Default delimiter comma(,)
Delimiter can be of colon( : ),semicolon (:),tab (t), pipe (|))
Writer() – write into the file
syntax
csv.writer(file)
Writer()
import csv
f1=open('new1.csv','w',newline='')
s_writer=csv.writer(f1)
s_writer.writerow(["Name","Location
"])
rec=[ ]
while True:
name=input("enter name:")
Location=input("enter location:")
lst=[name,Location]
rec.append(lst)
ch=input("do u want to enter more
records y/n: ")
if ch=='n':
break
s_writer.writerows(rec)
f1.close()
import csv
def read():
f1=open('new1.csv','r',newline='')
s_reader=csv.reader(f1)
for i in s_reader:
print(i)
f1.close()
read()
Reader ()
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file

More Related Content

What's hot

Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
Mr. Vikram Singh Slathia
 
1 cs xii_python_file_handling text n binary file
1 cs xii_python_file_handling text n binary file1 cs xii_python_file_handling text n binary file
1 cs xii_python_file_handling text n binary file
SanjayKumarMahto1
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
Edureka!
 
File handling in Python
File handling in PythonFile handling in Python
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
chapter-4-data-file-handlingeng.pdf
chapter-4-data-file-handlingeng.pdfchapter-4-data-file-handlingeng.pdf
chapter-4-data-file-handlingeng.pdf
SyedAhmed991492
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
Vikram Nandini
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
Md. Sohag Miah
 
File Handling in Python
File Handling in PythonFile Handling in Python
CSV Files-1.pdf
CSV Files-1.pdfCSV Files-1.pdf
CSV Files-1.pdf
AmitenduBikashDhusiy
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 

What's hot (20)

Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
1 cs xii_python_file_handling text n binary file
1 cs xii_python_file_handling text n binary file1 cs xii_python_file_handling text n binary file
1 cs xii_python_file_handling text n binary file
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
chapter-4-data-file-handlingeng.pdf
chapter-4-data-file-handlingeng.pdfchapter-4-data-file-handlingeng.pdf
chapter-4-data-file-handlingeng.pdf
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
12 SQL
12 SQL12 SQL
12 SQL
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
 
File Handling in Python
File Handling in PythonFile Handling in Python
File Handling in Python
 
CSV Files-1.pdf
CSV Files-1.pdfCSV Files-1.pdf
CSV Files-1.pdf
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 

Similar to CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file

pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
ARYAN552812
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
ToniyaP1
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
Ashwini Raut
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
vsol7206
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
kendriyavidyalayano24
 
03-01-File Handling.pdf
03-01-File Handling.pdf03-01-File Handling.pdf
03-01-File Handling.pdf
botin17097
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
yndaravind
 
File handling in C
File handling in CFile handling in C
File handling in C
Simplilearn
 
File Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handlingFile Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handling
abdulsamadbrohi461
 
File Handling
File HandlingFile Handling
File Handling
TusharBatra27
 
Data file handling in python introduction,opening &amp; closing files
Data file handling in python introduction,opening &amp; closing filesData file handling in python introduction,opening &amp; closing files
Data file handling in python introduction,opening &amp; closing files
Keerty Smile
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptx
AmitKaur17
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
Ananthi Palanisamy
 
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is hereCHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
sidbhat290907
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
Koteswari Kasireddy
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
Koteswari Kasireddy
 
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptxPOWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
samkinggraphics19
 
Filehadnling
FilehadnlingFilehadnling
Filehadnling
Khushal Mehta
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
ٖFaiXy :)
 
presentation_files_1451938150_140676.ppt
presentation_files_1451938150_140676.pptpresentation_files_1451938150_140676.ppt
presentation_files_1451938150_140676.ppt
ansariparveen06
 

Similar to CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file (20)

pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
 
03-01-File Handling.pdf
03-01-File Handling.pdf03-01-File Handling.pdf
03-01-File Handling.pdf
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
File handling in C
File handling in CFile handling in C
File handling in C
 
File Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handlingFile Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handling
 
File Handling
File HandlingFile Handling
File Handling
 
Data file handling in python introduction,opening &amp; closing files
Data file handling in python introduction,opening &amp; closing filesData file handling in python introduction,opening &amp; closing files
Data file handling in python introduction,opening &amp; closing files
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptx
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is hereCHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
 
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptxPOWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
POWER POINT FILE INPUT AND OUTPUT PRESENTATION.pptx
 
Filehadnling
FilehadnlingFilehadnling
Filehadnling
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
 
presentation_files_1451938150_140676.ppt
presentation_files_1451938150_140676.pptpresentation_files_1451938150_140676.ppt
presentation_files_1451938150_140676.ppt
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 

CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file

  • 1. CBSE CLASS 12 Ch-5 File Handling SasikalaJayaprakash
  • 2. INTRODUTION  A file in itself is bunch of byes stored on some storage device like hard –drive etc .  Files help in storing information permanently .
  • 3. TEXT FILES • A text file store information in ASC11 or unicode characters • line of text is terminated,(delimited )with a special character known EOL (end of line) • Default mode • Extn of text file is .txt • Translation occur
  • 5. Opening position of file pointer File modes Opening position of file pointer r , rb , r+ , rb+ , r+b Beginning of file W, wb, w+, wb+, w+b Beginning of file a+, ab , a+ , ab+, a+b End of file if file exist otherwise beginning of file
  • 6. Opening files <file _object name> =open (<file name >) <file_ object name> =open(<file name >,<mode>) with open <file_name > as <file_object with open (‘a.txt’ , ‘r’ ) as myfile myfile = open (‘a.txt’, ‘ r’ )
  • 7. READING FILES METHOD SYNTAX DESCRIPTION Read() <filehandle>. read([n]) Read at most n bytes; if no n is specified , reads the entire file , return form of string Readline() <filehandle>.readline([n]) Reads a line of input , if n is specified reads at most n bytes, returns in form of string Readlines() <filehandle> . readlines() Read all lines and return in a list
  • 8. Writing onto files Method Syntax Description write () <file handle>.write(str1) writes string str1 to file referenced by <file handle> writelines() <file handle>.writeline(L) write all strings in list L as lines to file referenced by <filehandle>
  • 9. Standard Input ,Output and error stream • Standard input device( stdin ) – reads from the keyboard • Standard output device (stdout) – prints to the display and can redirected as standard input • Standard error device(stderr) – same as stdout but normally only for errors
  • 10. Binary files  A binary file is just a file a that contain information in the same format in which the information is held in memory  There is no delimiter for a line  No translations occur required in binary files  Faster and easier for a program to read and write  Extn is .dat file
  • 11. Pickling and unpickling • pickling refers to the process of converting the structure(such as list or dict ) to a byte stream before writing to the file . Structure(list or dictionary) Pickling Byte stream
  • 12. pickle.dump () Used to write object into file syntax : pickle.dump(<structure>,fileobject) file object is the file handle of the file where you write the contents
  • 13. pickle.load() • used to read data from file • syntax : structure=pickle.load(fileobject)
  • 14. Load() import pickle def read(): f1=open('s2.dat','rb') try: while True: rec=pickle.load(f1) print(rec) except EOFError: f1.close() read()
  • 15. Dump() import pickle def write(): f1=open('s2.dat','wb') rec=[ ] while True mark1,mark2,mark3=0,0,0 r=int(input("enter rollno:")) n=input("enter name:") m1=int(input("enter mark1:")) m2=int(input("enter mark2:")) m3=int(input("enter mark3:")) a=(m1+m2+m3)/3 lst=[r,n,m1,m2,m3,a] rec.append(lst) pickle.dump(rec,f1) f1.close() write()
  • 16. CSV Files • CSV files are comma seperated values , each line of the file is data record .Each record consist of one or more fields seperated by commas .Data stores in the form of rows and columns • It is a text file • It is mainly useful in importing and exporting excel files into csv files and processing in python • File object , csv object to be created • Accessing is fast • Can store large amount of data • Extn is .csv
  • 17. Reader () - read from the file Syntax csv.reader (file , delimiter) Default delimiter comma(,) Delimiter can be of colon( : ),semicolon (:),tab (t), pipe (|)) Writer() – write into the file syntax csv.writer(file)
  • 18. Writer() import csv f1=open('new1.csv','w',newline='') s_writer=csv.writer(f1) s_writer.writerow(["Name","Location "]) rec=[ ] while True: name=input("enter name:") Location=input("enter location:") lst=[name,Location] rec.append(lst) ch=input("do u want to enter more records y/n: ") if ch=='n': break s_writer.writerows(rec) f1.close()