Path: blob/master/Python core/Day 3File Handling.ipynb
3074 views
Kernel: Python 3
File Handling
File handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on file.
In [16]:
In [13]:
Out[13]:
enter Name of file you want to open:ashi.txt
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-f06ddbf16757> in <module>()
2 file=input("enter Name of file you want to open:")
3 #file=open("Quiz.txt","r")
----> 4 a=file.read() # reads whole file
5 #b=file.read(10) # reads five letters
6 #c=file.readlines(3) # reads two lines
AttributeError: 'str' object has no attribute 'read'
In [15]:
Out[15]:
Data
with python
Data Handling
with python
In [26]:
Out[26]:
['Learn', 'Data', 'Science']
['with', 'python']
[]
['Data', 'Visualization']
Ques: Program to count number of lines in a file
In [21]:
Out[21]:
0 HI
1 THis is python
2 classsss
3 Welcomeall
4 study
Number of lines in file: 5
Ques: Program to find largest word in a file
In [30]:
Out[30]:
['HI', 'THis', 'is', 'pythonclasssss', 'Welcomeall', 'study']
The longest word in file = pythonclasssss and its length = 14 :
Ques : A Python program to get the file size of a plain file
In [22]:
Out[22]:
File size in bytes of a plain file= 48
Program to copy one file to another
In [23]:
Out[23]:
'abc.txt'
In [ ]: