Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:04+00:00 2026-06-18T05:21:04+00:00

I have 3 scripts. one is starttest.py which kicks the execution of methods called

  • 0

I have 3 scripts. one is starttest.py which kicks the execution of methods called in test.py. Methods are defined in module.py.

There are many print statements in each of file and I want to capture each print statement in my log file from Starttest.py file itself. I tried using sys.stdout in starttest.py file but this function only takes print statements from starttest.py file. It does not have any control on test.py and module.py file print statements.

Any suggestions to capture the print statements from all of the files in a single place only?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:21:06+00:00Added an answer on June 18, 2026 at 5:21 am

    Before importing anything from test.py or module.py, replace tye sys.stdout file object with one of your liking:

    import sys
    
    sys.stdout = open("test-output.txt", "wt")
    
    # Import the rest
    

    If you’re running on a Unix-like operating system, there is a safer method that does not need to replace the file object reference. Specially since overwriting sys.stdout does not guarantee that previous object is destroyed:

    import os
    import sys
    
    fd = os.open("test-output.txt", os.O_WRONLY | os.O_CREAT, 0644)
    os.dup2(fd, sys.stdout.fileno())
    os.close(fd)
    

    Note that the above trick is used by almost all daemonization implementations for Python.

    Even though not directly related, remember also that you can use your shell to redirect command output to a file (works on Windows too):

    python starttest.py >test-output.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two scripts that are called in one program, the first script creates
I have a one page web application, which means alot of javascript. External scripts
Many sites have scripts similar to the one below. These are put to stop
I have two scripts, that I have created. One which is for the desktop
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have two scripts running on the same page, one is the jQuery.hSlides.js script
I have 2 sql scripts, one is for fresh install and the other one
With my database upgrade scripts, I typically just have one long script that makes
I have scripts that have one-liners or sort scripts from other languages within them.
I have two jQuery scripts - One for inline form editing and the second

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.