How to read file in python | Sololearn: Learn to code for FREE!
+ 1

How to read file in python

I want to read each line from a .txt file and able to to access each word in a line with their index positions. there are two words in each line, words are separated with a tab space. Thanks u

3rd Jan 2020, 5:40 AM
Emmanuel Chweya
Emmanuel Chweya - avatar
2 Answers
+ 4
To open a file in python, you can use the built in 'open()' function Here's the basic syntax: file = open('filename.txt', 'r') Where the second parameter is the mode the file is open in. For more information, I recommend taking a look at this: https://www.w3schools.com/python/ref_func_open.asp
3rd Jan 2020, 6:09 AM
Brian R
Brian R - avatar
+ 1
thank you Brian R lemme check out the link
6th Jan 2020, 1:06 PM
Emmanuel Chweya
Emmanuel Chweya - avatar