File tree 1 file changed +3
-1
lines changed
1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change 7
7
# ‘rt’ will open for read in text mode
8
8
9
9
10
- # using open functionn to read content of a while
10
+ # Reading file contents
11
11
x = open ("sample.txt" , "r" ) # we can use single or double inverted comma's here
12
12
#open is a built in function
13
13
# by default its on "r" and ists not mandatory to mention id you want write or "w" then its mandatory
24
24
print (data )
25
25
x .close
26
26
27
+ # Writing to a file
27
28
f = open ("writingfile.txt" , "w" )
28
29
f .write ("here am writing a file " ) # Can be called multiple times
29
30
# am writing a file and without a file present at the stage but it will write and save in a new created file
30
31
f .close ()
31
32
33
+ # Appending to a file
32
34
f = open ("writingfile.txt" , "a" )
33
35
f .write ("here am appending a file " ) # if called multiple times it will append multiple times
34
36
f .close ()
You can’t perform that action at this time.
0 commit comments