From 218bcfe75d0f44eadd9c13ec5667dee29e02da9a Mon Sep 17 00:00:00 2001 From: ishan-sriv Date: Sun, 3 Mar 2019 23:41:21 +0530 Subject: [PATCH] Add lines 109-118(reading files) (#27795) * Add lines 109-118(reading files) * Update index.md --- guide/english/python/files-and-io/index.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guide/english/python/files-and-io/index.md b/guide/english/python/files-and-io/index.md index 421c7da8d5..ca2c69f1d0 100644 --- a/guide/english/python/files-and-io/index.md +++ b/guide/english/python/files-and-io/index.md @@ -110,6 +110,16 @@ Sample code to open a text file using the `with` statement: with open('hello_world.txt', 'w') as f: f.write('Hello World!') ``` +#### Reading files +There are many ways of reading a file. Reading a file fh is only possible if file is opened in read mode, the following are the options: + +fh.read(): read file as a single string + +fh.read(n): read n number of characters + +fh.readline(): read one line and end with \n + +fh.readlines(): read file as a list of strings and end with '\n' #### More Information: [Python Documentation - IO](https://docs.python.org/2/tutorial/inputoutput.html)