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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:08+00:00 2026-05-22T03:16:08+00:00

I am having trouble with a really simple problem. I’m trying to remove line

  • 0

I am having trouble with a really simple problem. I’m trying to remove line breaks in a file and send the output to a new file. This is my code:

infile = open('seq.txt', mode='r', encoding='utf-8')
lines = infile.readlines()
for line in lines:
    par = line.strip('\n')

outfile = open('seqpar.txt', mode='w', encoding='utf-8')
for line in lines:
    outfile.write(par)

When I run the above code, the contents of the outfile (seqpar.txt) is completely blank. I’ve tried to search for I/O tutorials online, but I can’t seem to locate any solutions to a similar problem. I’m really having trouble with understanding file I/O for some reason.Thanks in advance for the help.

  • 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-22T03:16:08+00:00Added an answer on May 22, 2026 at 3:16 am

    Other answers explain what’s wrong with your code. Here’s a more pythonic way of doing what you’re trying to do:

    with open('seq.txt', mode='r', encoding='utf-8') as infile:
        with open('seqpar.txt', mode='w', encoding='utf-8') as outfile:
            for line in infile:
                outfile.write(line.strip("\n"))
            # Or alternatively -- more efficient, but perhaps less pythonic:
            # outfile.write(infile.read().replace("\n", ""))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a really strange problem. I'm trying to download some file and store.
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I'm really having trouble with Allocatable array. I have to copy all information from
I must really be missing something obvious, but I'm having trouble with general use
I feel like the answer to this question is really simple, but I really
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying
For some reason I'm having trouble finding an answer to this, but it's a
I'm just learning about gtkmm for c++. I'm having trouble getting a simple TextBuffer
So, I'm having a little trouble trying to make a card reader work properly
I'm having trouble working with a data table in R. This is probably something

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.