Date: June 1, 2016
Python is able to support file read and manipulation. The essential functions for file manipulation will be discussed.
file_handler = open ('this_is_your_file.file_format')
file_handler = open ('this_is_your_file.file_format')
# file manipulation logic must be here
file_handler.close()
Note: Don't forget to close.
file_handler = open ('this_is_your_file.file_format')
# will get all the content from the file
file_content = file_hanlder.read()
# will get content of file line by line
file_content = file_hanlder.readline()
file_handler.close()
Note: The readline function will keep track which line the program is currently reading.
file_handler = open ('this_is_your_file.file_format', 'w')
file_hanlder.write(some_data)
file_handler.close()
file_handler = open ('this_is_your_file.file_format', 'w')
file_hanlder.truncate()
file_handler.close()
Note: As soon as a file is opened in write mode, the file is already truncated.
Almer Mendoza