Python tutorial-File input output

File input output

So far, we haven’t talked about writing data to a hard drive or reading data from it. In Python, the file input and output processes are simple . Opening a file
In Python, you can open a file by using open function. This function will return a file object: open(name[, mode[, buffering]])
The name is a mandatory argument. It is the file name (with full path) that you want to open for writing or reading. File mode argument
By default, if you don’t supply mode argument, the file is opened for reading only. There are some file modes that you will need. Please read the following table:
Mode Value Description
‘r’ Read only mode
‘w’ Write only mode
‘a’ Append mode
‘b’ Binary mode(for adding to other modes)
‘+’ Read/Write mode(for adding to other modes)


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.