Reputation: 309
I try to do the following,
file = open('test.txt', 'w+')
item = "hello"
file.write(item)
print(file)
When I run this program I get the following output,
<_io.TextIOWrapper name='test.txt' mode='w+' encoding='cp1252'>
Is there a way to open and then write in the file and then save it so I can use that new file somewhere else? Even though I have something written in the file, I still get this output.
Upvotes: 0
Views: 259
Reputation: 148
f = open("file.txt",'r+')
lines = f.readlines()
f.writelines(lines)
f.close()
Upvotes: 1