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

  • Home
  • SEARCH
  • 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 7765845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:15:54+00:00 2026-06-01T15:15:54+00:00

So I have a program which runs. This is part of the code: FileName

  • 0

So I have a program which runs. This is part of the code:

FileName = 'Numberdata.dat'
NumberFile = open(FileName, 'r')
for Line in NumberFile:
  if Line == '4':
    print('1')
  else:
    print('9')
NumberFile.close()

A pretty pointless thing to do, yes, but I’m just doing it to enhance my understanding. However, this code doesn’t work. The file remains as it is and the 4’s are not replaced by 1’s and everything else isn’t replaced by 9’s, they merely stay the same. Where am I going wrong?

Numberdata.dat is "444666444666444888111000444"

It is now:

FileName = 'Binarydata.dat'
BinaryFile = open(FileName, 'w')
for character in BinaryFile:
  if charcter == '0':
    NumberFile.write('')
  else:
    NumberFile.write('@')
BinaryFile.close()
  • 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-01T15:15:55+00:00Added an answer on June 1, 2026 at 3:15 pm

    You need to build up a string and write it to the file.

    FileName = 'Numberdata.dat'
    NumberFileHandle = open(FileName, 'r')
    newFileString = ""
    for Line in NumberFileHandle:
      for char in line: # this will work for any number of lines.
          if char == '4':
            newFileString += "1"
          elif char == '\n':
            newFileString += char
          else:
            newFileString += "9"
    NumberFileHandle.close()
    
    NumberFileHandle = open(FileName, 'w')
    NumberFileHandle.write(newFileString)
    NumberFileHandle.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which does a system call: latex somefile.latex This runs ok,
I have a program which runs an external, command line utility and reads the
I have a cgi python program which runs an os.system command and this command
I have a program which runs on a console and its Umlauts and other
I have an RMI program which runs fine on my computer, but when I
I have an MPI program which compiles and runs, but I would like to
I have a python program, which runs on the CPython implementation, and inside it
So I have a Linux program that runs in a while(true) loop, which waits
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have an erlang program which runs a server on a local machine and

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.