Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

Kindly check the below Python 3 script:

f1 = open('a.txt', 'r')

print(f1.readlines())

f2 = open('b.txt', 'r')

print(f2.readlines())

f3 = open('c.txt', 'r')

print(f3.readlines())

f4 = open('d.txt', 'r')

print(f4.readlines())``

f1.close()

f2.close()

f3.close()

f4.close()

When I am executing the above code, I am always getting the below error:

IOError: [Errno 32] Broken pipe

Kindly provide a solution for the above error.

1 Answer

0 votes
by (107k points)

I think the below method will help you out in resolving your problem:

import sys

with open('a.txt', 'r') as f1:

    for line in f1:

        sys.stdout.write(line)

If you are a beginner and want to know more about Python, then do refer to the Python training course.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 5, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...