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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:30:58+00:00 2026-06-13T15:30:58+00:00

I noticed the following using Python 2.5.2 (does not occur using 2.7): #!/usr/bin/python import

  • 0

I noticed the following using Python 2.5.2 (does not occur using 2.7):

#!/usr/bin/python

import sys

for line in sys.stdin:
   print line,

Output:

$ echo -e "one\ntwo\nthree" | python test.py
$ one
$ two
$ three

as expected. However, if I import subprocess to the this script:

#!/usr/bin/python

import sys
import subprocess

for line in sys.stdin:
   print line,

Output:

$ echo -e "one\ntwo\nthree" | python test.py
$ two
$ three

What happened to the first line of output?

Update:

I think I may have discovered the root of the problem. I had a file named time.py in my cwd. A time.pyc is being created every time I run the script with subprocess imported, suggesting that ./time.py is also being imported. The script runs normally if I delete the .pyc and time.py files; however, there is still the question of why a subprocess import would cause ./time.py to be imported as well?

I have narrowed it down even further to the exact line in time.py that causes the strange behaviour. I have stripped down the working dir and file content to just that which affects the output:

test.py

#!/usr/bin/python

import sys
import subprocess

for line in sys.stdin:
   print line,

time.py

#!/usr/bin/python

import sys

for line in sys.stdin:
   hour = re.search(r'\b([0-9]{2}):', line).group(1)

Running test.py with any kind of input results in the first line of output being omitted and time.pyc being created.

  • 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-13T15:31:00+00:00Added an answer on June 13, 2026 at 3:31 pm

    Sounds like your local time.py will be imported instead of the global time module. You might want to rename it, or at least start checking if it was run as a script or imported as a module.

    This will prove it for you if you want to test it.

    #!/usr/bin/python
    
    import sys
    
    # Test that script was run directly
    if __name__=='__main__':
        for line in sys.stdin:
           hour = re.search(r'\b([0-9]{2}):', line).group(1)
    else:
        print 'Imported local time.py instead of global time module!'
        sys.exit(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed the following behavior in the following code (using threading.Timer class): import threading
I am using the embedded version of jetty. I have noticed the following: in
Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
I just started with Google App Engine using python and I was following a
i have noticed when using python gnupg, that if i sign some data and
I am using python zlib and I am doing the following: Compress large strings
I am trying to convert hex value to float using (Python 2.7) the following
When I was reading this tutorial I noticed the following performance tip about using
I'm crossfading between two views using UIView animation. I've noticed the following surprising fact:
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)

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.