Page 455 - CITS - Computer Software Application -TT
P. 455

COMPUTER SOFTWARE APPLICATION - CITS













           •  1. Writing to a File: To write data to a file, you need to open the file in write mode (‘w’). You can then use the
              ‘write()’ method to write data to the file.







           •  1. Closing a File: After performing file operations, it’s important to close the file using the ‘close()’ method. This
              releases system resources associated with the file.





           •  1. Appending to a File: To append data to an existing file, you can open the file in append mode (‘a’) and use
              the’ write()’ method.







           •  1. Using with Statement: Python’s with statement is preferred for file handling as it automatically closes the
              file when the block is exited, ensuring proper cleanup.









           •  These are the fundamental operations for handling files in Python. Additionally, Python also provides modules
              like  ‘os,  shutil’,  and  ‘os.path’  for  performing  more  advanced  file-related  operations  like  file  manipulation,
              directory handling, and path manipulations.

































                                                           442

                             CITS : IT&ITES - Computer Software Application - Lesson 120 - 137
   450   451   452   453   454   455   456   457   458   459   460