How to read all the lines from a text file in Python

2 Answers

0 votes
file = open("d:\\data.txt", "r")

for line in file.readlines():
    print(line, end="")

'''
run:
 
C++
VB.NET
C#
Java
PHP
Python

'''

 



answered Nov 15, 2018 by avibootz
0 votes
f = open("d:\data.txt", "rt")  # OR f = open("d:\data.txt")

for line in f:
    print(line)


'''
run:
 
C++

VB.NET

C#

Java

PHP

Python

'''

 



answered Nov 26, 2018 by avibootz

Related questions

1 answer 179 views
2 answers 243 views
1 answer 262 views
1 answer 183 views
1 answer 174 views
1 answer 174 views
2 answers 270 views
270 views asked Oct 24, 2018 by avibootz
...