Path: blob/master/Python Basics/File Handling-Day4.ipynb
3074 views
Kernel: Python 3
In [ ]:
In [ ]:
In [5]:
Out[5]:
09-20-16
16/09/20|13:47:30
In [8]:
Out[8]:
20/09/16|13:53:22
In [11]:
Out[11]:
Wednesday/September|Wed/Sep
13:57:PM
+0530
530
In [7]:
Out[7]:
Current date and time: 2020-09-16 13:50:32.358677
Current year: 2020
Month of year: September
Week number of the year: 37
Weekday of the week: 3
Day of year: 260
Day of the month : 16
Day of week: Wednesday
In [9]:
Out[9]:
Wed Sep 16 13:54:37 2020
Wed Sep 16 13:54:47 2020
In [ ]:
In [ ]:
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.
Key Words: open(), "w","r","a","read(5)",readlines()
open(): "r": read(oPENING, ERROR IF FILE IS NOT THERE)
"t": Text: Default value(Text mode)
"b": Binary: Binary mode(Images)
In [30]:
Out[30]:
<_io.TextIOWrapper name='C:\\Users\\suyashi144893\\Documents\\data Sets\\Mobilevariants.txt' mode='r' encoding='cp1252'>
In [39]:
In [40]:
Out[40]:
pythonpython
python
In [41]:
Out[41]:
enter Name of file you want to open:dat.txt
dat.txt
In [3]:
Out[3]:
HI
THis is python
classsss
Welcomeall
study
In [4]:
Out[4]:
['HI']
['THis', 'is', 'python']
['classsss']
['Welcomeall']
['study']
Ques: Program to count number of lines in a file
In [ ]:
Ques: Program to find largest word in a file
In [ ]:
To get the file size of a plain file
In [6]:
Out[6]:
File size in bytes of a plain file = 48 bytes
To copy one file to another
In [ ]: