In: Computer Science
How algorithms address object-oriented classes and objects. What is the File object? How are File objects used in algorithms?
175 words minumum please :)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
A file object allows us to use, access and manipulate all the
user accessible files. One can read and write any such files.
When a file operation fails for an I/O-related reason, the
exception IOError is raised. This includes situations where the
operation is not defined for some reason, like seek() on a tty
device or writing a file opened for reading.
Files have the following methods:
open(file_address, access_mode)
Examples of accessing a file: A file can be opened with a
built-in function called open(). This function takes in the file’s
address and the access_mode and returns a file object.
There are different types of access_modes:
r: Opens a file for reading only r+: Opens a file for both reading and writing w: Opens a file for writing only w+: Open a file for writing and reading. a: Opens a file for appending a+: Opens a file for both appending and reading
When you add 'b' to the access modes you can read the file in binary format rather than the default text format. It is used when the file to be accessed is not in text.
Attributes:
Kindly revert for any queries
Thanks.