1
00:00:00,420 --> 00:00:04,270
Hello and welcome to this lecture of our course.

2
00:00:04,290 --> 00:00:07,960
open files in python

3
00:00:08,130 --> 00:00:12,500
We should open files in python  before we can read or write.

4
00:00:12,870 --> 00:00:25,340
So could you open function in Python to open files that defied equal of of embedded PCs of double codes.

5
00:00:25,410 --> 00:00:28,980
open double quotes File underscore name

6
00:00:29,280 --> 00:00:36,710
close double quotes comma  double quotes open mode close double quotes

7
00:00:39,590 --> 00:00:54,600
open moods are default only open modes R
rb binary read and write mode


8
00:00:55,100 --> 00:01:12,090
R B plus finally read and write
w default write only mode
wb binary write only  and w+

9
00:01:12,180 --> 00:01:24,090
read and write default mode
wb+ is  binary read and write
B binary mode
a append read and write

10
00:01:24,090 --> 00:01:26,980
create the file if the file not exists.

11
00:01:28,580 --> 00:01:33,340
X creates the file if the file not exists mode.

12
00:01:33,900 --> 00:01:35,550
file.read( ):

13
00:01:35,930 --> 00:01:45,760
We use this method to read over the file or lines of the file f equal  open parentheses

14
00:01:45,800 --> 00:01:51,000
file underscore name double quotes comma double quotes open mode close double quotes

15
00:01:51,190 --> 00:02:00,210
double quotes open mode close double quotes close parenthesis f equal open open parenthesis open double quotes file_name dote text close parenthesis and r

16
00:02:01,000 --> 00:02:10,680
and r  print f dote print

17
00:02:10,760 --> 00:02:14,050
f dote read 6 print f dote read 10

18
00:02:14,180 --> 00:02:23,530
Then we will read and print the first two or six or ten lines for our file.

19
00:02:23,620 --> 00:02:24,680
Find dote read line.

20
00:02:25,910 --> 00:02:34,360
We use this method to read the file line by line f equal open file_name and open mode.

21
00:02:34,910 --> 00:02:37,910
f equal open

22
00:02:37,910 --> 00:02:44,360
file_name.text and r  print f.readline ( )

23
00:02:44,410 --> 00:02:48,180
loop file function we use with open file

24
00:02:48,190 --> 00:02:58,320
Function to read our file  f equal open file_name and open mode

25
00:02:58,560 --> 00:03:12,590
f equal open file_name.txt and r
for line in file print line


26
00:03:12,590 --> 00:03:22,910
if.close( ) we use this method to close the file which is a good practice to avoid system memory block by the files we opened

27
00:03:23,000 --> 00:03:33,050
f equal open  ("file_name", "open mode")

28
00:03:33,500 --> 00:03:50,730
f equal open("file_name.txt", "r")
print f dote readline( )
f dote close( )

29
00:03:50,760 --> 00:03:59,370
to remove the file we have opened and closed as full data underscore file equal open

30
00:03:59,400 --> 00:04:07,340
("file_name","open mode")

31
00:04:07,740 --> 00:04:16,320
f equal  open("file_name.txt", "r")

32
00:04:16,680 --> 00:04:26,380
f equal  open("file_name.txt", "r")
print(f.readline( ))

33
00:04:26,520 --> 00:04:34,440
print(f.readline( ))
f dote close( )

34
00:04:34,610 --> 00:04:35,650
f dote close( )

35
00:04:36,590 --> 00:04:45,690
import os
os.remove("file_name.txt")

36
00:04:45,860 --> 00:04:58,320
so we can move our file as this method from opening to close to remove if the file is a file isn't exist

37
00:04:58,730 --> 00:05:00,710
we will get Error

38
00:05:01,080 --> 00:05:03,110
Thank you for watching.

39
00:05:03,120 --> 00:05:04,980
Hope you enjoy this course.
Don't forget to review this course.
