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

0 votes
1 answer
0 votes
1 answer
asked Dec 20, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer

Browse Categories

...