File tree 1 file changed +35
-0
lines changed 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ __author__ = 'Avinash'
2
+ import os
3
+
4
+ # Different file attributes
5
+ file_attributes = open ("test.txt" , "wb" )
6
+ print ("Name of the file: " , file_attributes .name )
7
+ print ("Closed or not : " , file_attributes .closed )
8
+ print ("Opening mode : " , file_attributes .mode )
9
+ file_attributes .close ()
10
+
11
+ # Write to a file in binary format
12
+ file_write_bytes = open ("test.txt" , "wb" )
13
+ file_write_bytes .write (bytes ("Python is a great language." , 'UTF-8' ))
14
+ file_write_bytes .close ()
15
+
16
+ # Write to a file
17
+ file_write = open ("test.txt" , "w" )
18
+ file_write .write ("Python is a great language." )
19
+ file_write .close ()
20
+
21
+ # Reading from a file
22
+ file_read = open ("test.txt" , "r+" )
23
+ text = file_read .read ()
24
+ print ("Read String is : " , text )
25
+ file_read .close ()
26
+
27
+ # Append to a file
28
+ file_append = open ("test.txt" , "a" )
29
+ file_append .write ("\n Python is a powerful language." )
30
+ file_append .close ()
31
+
32
+ # Delete a file
33
+ os .remove ("test.txt" )
34
+
35
+
You can’t perform that action at this time.
0 commit comments