Back

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

In python 2.7, I can able to do:

file('text.txt', 'w').write('some text')

Yet, in python 3 I need to utilize the open function, so I can't keep in touch with a file on a solitary line any longer

f = open('text.txt', 'w')

print('some text', file = f)

f.close()

I don't know why they removed the file function here?

1 Answer

0 votes
by (26.4k points)

Below codeworks a similar way and open has been the authoritative method to open a document (and consequently make a file instance) for quite a while, even on Python 2.x.

open('text.txt', 'w').write('some text')

Interested to learn python in detail? Come and Join the python course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...