Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File IO Help
#2
You should choose another IDE. Python.org includes Idle with python, but it is a poor IDE and really shouldn't be used.
Although choice of an IDE is personal, VSCode is highly recommended, easy to install and learn, and offers many extensions.
You can install and try it out using this installation procedure: https://python-forum.io/Thread-VS-Code-f...ght=VSCode

as an FYI, a better way to open and read files is with the context manager 'with' statement:
def main():
    var = 123
 
    # Writes
    with open('test.py', 'w') as fo:
        fo.write('num = {}'.format(var))
No close necessary
this can be simplified further:
def main():
    # Writes
    with open('test.py', 'w') as fo:
        fo.write('num = {}'.format('123'))
Reply


Messages In This Thread
File IO Help - by jarrod0987 - Dec-13-2018, 09:14 AM
RE: File IO Help - by Larz60+ - Dec-13-2018, 10:18 AM
RE: File IO Help - by gehrenfeld - Dec-13-2018, 11:52 AM
RE: File IO Help - by Larz60+ - Dec-13-2018, 03:37 PM
RE: File IO Help - by gehrenfeld - Jan-27-2019, 07:01 PM
RE: File IO Help - by Larz60+ - Jan-27-2019, 07:13 PM

Forum Jump:

User Panel Messages

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