Python Forum
Redircet output of Python script to .txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redircet output of Python script to .txt file
#5
what i have done many times, because i don't know if it is safe to replace sys.stdout, and because i am running on Linux, is open the file and get the file descriptor, and replace stdout at that layer like:
    if fd!=1:
        os.dup2(fd,1)
        os.close(fd)
i usually sys.stdout.flush() before that for consistent output.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: Redircet output of Python script to .txt file - by Skaperen - May-05-2019, 11:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to feed python script of a file absolut 6 1,428 Jan-11-2025, 07:03 AM
Last Post: Gribouillis
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 8,520 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python Script to convert Json to CSV file chvsnarayana 8 5,107 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 2,208 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 2,138 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Formatting to output file Mark17 2 2,127 Jan-13-2022, 09:06 PM
Last Post: BashBedlam
Photo how I write the output into xml file in python? 3lnyn0 1 4,209 Oct-31-2021, 05:40 PM
Last Post: Gribouillis
  Showing and saving the output of a python file run through bash Rim 3 6,009 Oct-06-2021, 10:48 AM
Last Post: gerpark
  Real-Time output of server script on a client script. throwaway34 2 2,963 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 3,449 Feb-05-2021, 04:37 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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