Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I have the 2 files in my folder:

text.txt

main.py

I want to show a text written in text.txt in the terminal when the main.py is run. How can I do this?

1 Answer

0 votes
by (36.8k points)
edited by

Use the below code:

with open('text.txt', 'r') as f:

    print(f.read())

Learn Python for Data Science Course to improve the technical knowledge.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers

500 comments

108k users

Browse Categories

...