0

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.

William Denman
  • 3,046
  • 32
  • 34
ruthless
  • 309
  • 3
  • 13

1 Answers1

1
f = open("file.txt",'r+')
lines = f.readlines()
f.writelines(lines)
f.close()
Tim
  • 11,710
  • 4
  • 42
  • 43