Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newby to Pyhon
#3
with open('file.txt', 'r') as out_file:
     print(out_file.write('hello'))
That way you don't have to use close() after opening the file. It closes automaticaly. The with statement is called context manager.

Writing to a file:
with open('file.txt', 'w') as in_file:
    in_file.write('hello')
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Newby to Pyhon - by garich01 - Aug-31-2017, 08:19 AM
RE: Newby to Pyhon - by snippsat - Aug-31-2017, 08:30 AM
RE: Newby to Pyhon - by garich01 - Aug-31-2017, 09:02 AM
RE: Newby to Pyhon - by wavic - Aug-31-2017, 08:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a C Func though Pyhon Script using DLL file which is created for C file. CMMouli 4 4,809 Feb-18-2017, 05:06 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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