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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:04:17+00:00 2026-06-01T18:04:17+00:00

This is a bit strange. My program isn’t able to write the output to

  • 0

This is a bit strange. My program isn’t able to write the output to a file. Its even not showing any error. I simultaneously used standard output and found that its showing..

This is my code: (Python 2.7)

#!/usr/bin/env python


import re

def isRecycled(n,m):
    n = str(n)
    m = str(m)

    try:
        ...........
        ...........
        My Code.

    except ValueError:
        return False

ip = open("C-small-attempt0.in", "r")
op = open("output.txt", "a")
for num, eachLine in enumerate( ip.readlines()[1:] ):
    ......
    ......
    My code

    ## This is WORKING
    print "Case #%d: %d" %(num+1, count)

    ## This is NOT Working
    op.write("Case #%d: %d" %(num+1, count))

Can anyone tell me why this is not writing to the file.

I tried to use "w+", "w" modes and also writelines() method but they didn’t work.

Edited

However, it worked when I closed the file using op.close()

  1. Why this is happening? (I didn’t encounter it previously)
  2. Does python immediately write to the file as soon as it finds op.write()?
  • 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-01T18:04:18+00:00Added an answer on June 1, 2026 at 6:04 pm

    You need to close the file for it to write to disk. Add op.close() to the end of your code.

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

Sidebar

Related Questions

This problem is a bit strange. Why is showed Is not null, if the
I know this is a bit strange and believe me it's not the way
I came across this strange bit of CSS tonight... display: inline !ie; Now I've
In the following code, this line is a bit strange to me: var x=document.forms[myForm][fname].value;
I am a bit puzzled by this strange behavior on CentOs 5.4 when starting
I think this one is silly question, but it was a bit strange for
This is strange enough I'm not sure how to search for an answer. I
java.lang.ClassNotFoundException: com.hazelcast.core.Hazelcast This bit is strange though, because i've added hazelcast-1.8.5.jar to the classpath
This one may be a bit strange. I have a solution in Visual Studio
This is a bit of a strange question, but I thought people here might

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.