Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating file from editor
#6
f.read('hello world')
It's just f.read().
The point of using with open() is that the file will be closed automatically.
So trow away all close()
with open('bacon.txt', 'w') as f:
    f.write('hello world')

with open('bacon.txt') as f:
    print(f.read())
Output:
hello world
Reply


Messages In This Thread
Creating file from editor - by Truman - May-19-2018, 09:09 PM
RE: Creating file from editor - by snippsat - May-19-2018, 09:39 PM
RE: Creating file from editor - by volcano63 - May-19-2018, 09:39 PM
RE: Creating file from editor - by Truman - May-19-2018, 10:01 PM
RE: Creating file from editor - by volcano63 - May-19-2018, 10:09 PM
RE: Creating file from editor - by snippsat - May-19-2018, 10:17 PM
RE: Creating file from editor - by Truman - May-19-2018, 10:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,560 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Creating csv files from Excel file azizrasul 40 6,358 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Creating file with images BobSmoss 1 1,455 Jan-08-2022, 08:46 PM
Last Post: snippsat
  Music Notation editor; how to build the editor? direction to go? philipbergwerf 1 1,798 Jan-01-2022, 04:56 PM
Last Post: Larz60+
  Creating csv file from another file pisike 0 1,649 Nov-24-2020, 02:02 PM
Last Post: pisike
  Creating Conda env from requirments.txt file ErnestTBass 7 16,255 Apr-23-2020, 06:57 PM
Last Post: snippsat
  Creating a pdf from file DT2000 4 2,413 Apr-03-2020, 07:16 PM
Last Post: DT2000
  Internal Server Error 500 on creating .py file patrickluethi 0 1,811 Aug-02-2019, 01:57 PM
Last Post: patrickluethi
  python script file not opening in IDLE editor srm 2 4,458 Jun-23-2019, 08:45 AM
Last Post: Larz60+
  Creating Dictionary form LOG /text file DG1234 7 5,683 Feb-13-2019, 08:08 PM
Last Post: DG1234

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020