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 7735903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:37:01+00:00 2026-06-01T07:37:01+00:00

Ok.. So probably an example is a good way to explain this problem So

  • 0

Ok.. So probably an example is a good way to explain this problem

So I have something like this:

if __name__=="__main__"
    result = foobar()
    sys.stdout.write(str(result))
    sys.stdout.flush()
    sys.exit(0)

Now this script is being called from a ruby script.. and basically it parses the result there.
But foobar() has a lot of print statments.. and stdout flushes all those prints as well.
Is there a way (besides logging mathods) I can modify something over here which automatically suppresses those prints and just flushes this result??
Thanks

  • 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-01T07:37:02+00:00Added an answer on June 1, 2026 at 7:37 am

    You want to shadow (or otherwise hide) the stdout temporarily. Something like this:

    actualstdout = sys.stdout
    sys.stdout = StringIO()
    result = foobar()
    sys.stdout = actualstdout
    sys.stdout.write(str(result))
    sys.stdout.flush()
    sys.exit(0)
    

    You need to assign something that is file-like to sys.stdout so that other methods can use it effectively. StringIO is a good candidate because it doesn’t require disk access (it’ll just collect in memory) and then is discarded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably best shown with an example. I have an enum with attributes:
This has probably been asked before, but I can't find a good way of
What's a good way to do this? Seems like I could use a combination
This is probably explained more easily with an example. I'm trying to find a
Disclaimer: This question is strictly academic. The example I'm about to give is probably
This is probably a dumb question, but I can't seem to find a good
I've found some good examples of functors on SO like this one, and all
I should probably not ask a generic question with a specific example, but I
Probably a noob question, but I'll go for it nevertheless. For sake of example,
I'm probably asking the question badly, so I'm going to give an example. I

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.