File Input &outputs
File Input &outputs
File objects can be used not only to access normal disk files,
but also any other type of "file"that uses that abstraction.
The open() built-in function returns a file object which is then
used for all operations.
Operating systems like Unix even feature files as an underlying
File Objects and architectural interface for communication.
File Built-in Function [open()]
file_object = open(file_name,access mode='r', buffering=-1)
same file open modes used for the C library functionfopen().
r open for read
w open for write (truncate if necessary)
a open for write (start at EOF, create if necessary)
r+ open for read and write
w+ open for read and write ("w" )
File Mode a+ open for read and write ("a" )
Operation rb open for binary read
wb open for binary write ( "w")
ab open for binary append ( "a")
rb+ open for binary read and write ( "r+")
wb+ open for binary read and write ( "w+")
ab+ open for binary read and write ( "a+")
fp = open('/etc/motd') #open file for read