Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add stdout to text file
#4
I figured this out a while ago. Thought I would share the solution for future browsers/google searchers:

file_count = 0
count = 0

def write_file():
    global file_count, count, sfile
    if(count > 0):
        call_close()
        file_count += 1
        count = 0
    else:
        call_close()
        count += 1

def call_close():
    global file_count, ffilename
    with open(f"{wrkDir}\\sfile{file_count}.txt", "a+") as text_file:
        text_file.write("file ")
        text_file.write(f"'{clipOrig}\\{ffilename}'")
        text_file.write("\n")
        text_file.close()
Reply


Messages In This Thread
Add stdout to text file - by maxtimbo - Jan-28-2019, 03:09 AM
RE: Add stdout to text file - by ichabod801 - Jan-28-2019, 03:57 AM
RE: Add stdout to text file - by maxtimbo - Jan-28-2019, 02:45 PM
RE: Add stdout to text file - by maxtimbo - Feb-05-2019, 12:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 482 Jan-26-2024, 07:26 PM
Last Post: snippsat
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,130 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Performance options for sys.stdout.writelines dgrunwal 11 3,142 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,687 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,012 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,372 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  changing stdout and stderr Skaperen 4 2,700 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,414 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  saving data from text file to CSV file in python having delimiter as space K11 1 2,410 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Get stdout of a running process yok0 0 3,032 Aug-20-2020, 10:12 AM
Last Post: yok0

Forum Jump:

User Panel Messages

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