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
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,670 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python Script to convert Json to CSV file chvsnarayana 8 2,747 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 1,231 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 1,299 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
Photo how I write the output into xml file in python? 3lnyn0 1 2,361 Oct-31-2021, 05:40 PM
Last Post: Gribouillis
  Showing and saving the output of a python file run through bash Rim 3 2,632 Oct-06-2021, 10:48 AM
Last Post: gerpark
  Real-Time output of server script on a client script. throwaway34 2 2,149 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 2,459 Feb-05-2021, 04:37 PM
Last Post: nilamo
  Import output from python script to another varietyjones 1 1,978 Oct-12-2020, 09:07 PM
Last Post: bowlofred
  python script to Batch File biprabu 1 2,127 Sep-09-2020, 01:49 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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