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 200 views
2 answers 254 views
1 answer 273 views
1 answer 196 views
1 answer 188 views
1 answer 184 views
2 answers 286 views
286 views asked Oct 24, 2018 by avibootz
...