In python 2.7 I was able to do:
file('text.txt', 'w').write('some text')
But in python 3 I have to use the open function, so I cannot write to a file on a single line anymore.
f = open('text.txt', 'w')
print('some text', file = f)
f.close()
Why did they remove the file
function?
open('text.txt', 'w').write('some text')
works the same way and open
has been the canonical way to open a file (and hence create a file
instance) for a long time, even on Python 2.x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With