E
E
Emil Timerbaev2020-09-07 13:59:39
Python
Emil Timerbaev, 2020-09-07 13:59:39

How to display the entire contents of a file?

How to display the entire contents of the file, I need the code to be reduced to 1-2 lines, so

with open('g.txt', 'r') as f
A=f.read()
print (A)
not suitable, for a better explanation, I need to combine the first lines of the code I presented into one

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PavelMos, 2020-09-07
@MrDlop

the same can be shortened:

with open('g.txt', 'r') as f: 
    print(f.read())

or
with open('g.txt', 'r') as f: print(f.read())

V
Vladimir Kuts, 2020-09-07
@fox_12

print(open('g.txt', 'r').read())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question