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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:02:24+00:00 2026-06-14T01:02:24+00:00

Possible Duplicate: Replace four letter word in python I want write a file in

  • 0

Possible Duplicate:
Replace four letter word in python

I want write a file in the python shell, run a program in it, and then close the file.

Here is the code I have right now.

def censor(fileName):
    file = open(fileName, "r")
    for i in len(myList):
        censoredFile = open("censored.txt", "w")
        outputFile.write(censoredFile)
    outputFile.close()

The program I want to run isn’t in the program yet because I’m just trying to figure out how to deal with files. I have some programming experience but not a lot with files. Any input would be appreciated.

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-14T01:02:25+00:00Added an answer on June 14, 2026 at 1:02 am

    This is the code you need to read a file, replace all the four letter word and write the final result into a different file.

    def censor(fileName):
        output_content = ""
        with open(fileName, "r") as input_file:
            with open("censored.txt", "w") as output_file:
                output_content = ""
                for line in input_file:
                    output_content += ' '.join([word if len(word) != 4 else "****" for word in line.split(" ")])
                output_file.write(output_content)
    

    It should be it.

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

Sidebar

Related Questions

Possible Duplicate: Find and Replace more than 1 word? I want to use jQuery
Possible Duplicate: How do I write a regex to find and replace मेरा नाम
Possible Duplicate: Editing a text file in place through C# I need to replace
Possible Duplicate: php regular expression help? hi, i want to replace i like apple
Possible Duplicate: replace multiple placeholders with php? I've got a .txt-file working as a
Possible Duplicate: Eclipse Replace text in all Classes? I want to replace all instances
Possible Duplicate: Find and Replace Inside a Text File from a Bash Command I've
Possible Duplicate: What is the best way to replace the file browse button in
Possible Duplicate: Python replace multiple strings I am looking to replace , \r ,
Possible Duplicate: How to replace a string in an existing file in Perl? 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.