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 310 views
2 answers 395 views
1 answer 375 views
1 answer 296 views
1 answer 285 views
1 answer 278 views
2 answers 439 views
439 views asked Oct 24, 2018 by avibootz
...