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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:13:08+00:00 2026-05-29T23:13:08+00:00

We have this good answer for how to read stdin. But I don’t understand

  • 0

We have this good answer for how to read stdin.

  1. But I don’t understand how do I run the python code so it will read from a file as stdin?
  2. Is print is like stdout?

I ask it cause I saw this order in facebook demo puzzle:

NOTE: You need to write the full code taking all inputs are from stdin
and outputs to stdout If you are using “Java”, the classname is
“Solution”

  • 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-05-29T23:13:09+00:00Added an answer on May 29, 2026 at 11:13 pm

    When you are reading from stdin, you have three basic options:

    • type stuff manually:

      $ python hello.py
      asfasfasf
      asfasfasfasfasf
      <TYPE CONTROL-D TO END STREAM>
      
    • Using <:

      $ python hello.py < inputfile.txt
      
    • Using the output from a previous command:

      $ cat inputfile.txt | grep oranges | python hello.py
      

    All three of these will give you input via stdin.


    After editing your question, you are no longer asking the same question. Here is the answer to your new questions:

    1. You can do sys.stdin = open('inputfile.txt') to have the input file look like stdin. Make sure this is what you want. From your homework prompt, it sounds like my above solution is what you want.
    2. print writes to stdout.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Emacs. I have googled this but no good answer there.
I have heard this concept used frequently, but I don't have a really good
So basically, this is what I have. But is this a good practice? I
I have no good title for this question, but my problem is to set
I know that when I read the answer to this I will see that
Good day, I've done some research looking for this answer, but haven't had much
I've read this Android save app settings/data in Internal/External Storage but I don't think
So I am obviously not a very good programmer. I have written this small
Googling this does little good, as you can imagine. Does anyone have resources that
I'm wondering if this is a good design. I have a number of tables

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.