Skip to content

Commit c277a09

Browse files
committed
Python Course
1 parent 01134dc commit c277a09

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

File.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@
2525
# for third line you have to write this function again
2626
printLine=line.readline() #this print only first line of file
2727
print(printLine)
28-
line.close()
28+
line.close()
29+
30+
31+
32+
## Now How to write or create a new file using ".write()" function
33+
letFile= open("mydata.txt",'w') #we have not any file with "mydata.txt" than it will create this file
34+
Details= letFile.write("Make this file with name mydata")
35+
letFile.close()
36+
37+
# Now add other text in file "mydata.txt" with appending "a" i=use in ".open()" function
38+
Addtext=open('mydata.txt','a')
39+
done= Addtext.write('file is create with this we can add as much as data we want to write in this file using ".open(file_name,"a") than you can append data.')
40+
Addtext.close()#after this our file is updated you can check in that file.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,22 @@
483483
484484
3. Opening a File
485485
- Python has "open()" function for opening file.this is built in function.
486+
# Modes to open files
487+
1. r --> for read file
488+
2. w --> to write file
489+
3. + --> to update file
490+
4. a --> to appending file
491+
5. rb --> to open file in binary mode
492+
6. rt --> to opne file in text mode
493+
494+
# Read file in python-
486495
1. for use this you have to pass two parameters
487496
**Filename** or **mode**
488497
489498
```
490499
open("file_name","command")
491500
```
492-
**command can be - read, write, update and delete**
501+
**command can be - read, write, update and delete**
493502
494503
2. Functions to "read" a file
495504
1. ".read()" to read all content.
@@ -519,4 +528,17 @@
519528
letRead=file.readline()
520529
print(letRead)
521530
file.close()
522-
```
531+
```
532+
# Write file in python -
533+
1. for use this use this function syntax is:
534+
```
535+
letFile= open("mydata.txt",'w')
536+
Details= letFile.write("Make this file with name mydata")
537+
letFile.close()
538+
```
539+
2. to append data in this file: "a" use as append command
540+
```
541+
letFile= open("mydata.txt",'a')
542+
Details= letFile.write("Make this file with name mydata")
543+
letFile.close()
544+
```

mydata.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make this file with name mydatafile is create with this we can add as much as data we want to write in this file using ".open(file_name,"a") than you can append data.

0 commit comments

Comments
 (0)