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 191 views
2 answers 250 views
1 answer 269 views
1 answer 191 views
1 answer 181 views
1 answer 180 views
2 answers 280 views
280 views asked Oct 24, 2018 by avibootz
...