Python Forum
[PyGUI] How to store continous output into a text file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] How to store continous output into a text file?
#2

  1. Use BBCode
  2. Use Python 3.x or from __future__ import print_function
  3. Open a file in append mode.
  4. Use a context manager:
    with open('file', 'a') as fd:
        # code
        pass
    # leaving the block, guarantees that the file is closed
  5. Use fd.write('your data')
  6. Alternative you can use the print function. The function takes different arguments/keywords. The file keyword is the fileobject, where the print function writes it output. Additionally a newline is added automatic. You can also control sep (seperator) and end (newline).
    # inside the with block
    print('your data', file=fd)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: How to store continous output into a text file? - by DeaD_EyE - Aug-24-2018, 12:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Kivy] Create a function to store text fields and drop downs selection in KivyMD floxia 0 1,858 Dec-18-2022, 04:34 AM
Last Post: floxia
  Active tkinter text output during loop dvanommen 2 11,022 Oct-18-2019, 02:23 PM
Last Post: dvanommen

Forum Jump:

User Panel Messages

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