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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:38:39+00:00 2026-06-17T17:38:39+00:00

I need help in how to connect multiple lines from a txt file into

  • 0

I need help in how to connect multiple lines from a txt file into one single line without white spaces

The text file is consisting of 8 lines and each single line has 80 characters, as showing:

a busy cat
(source: gulfup.com)

Here is the code that I used, but my problem is that I am not able have all the lines connected with NO white spaces between them:

inFile = open ("text.txt","r") # open the text file
line1 = inFile.readline() # read the first line from the text.txt file
line2 = inFile.readline() # read the second line from the text.txt file
line3 = inFile.readline()
line4 = inFile.readline()
line5 = inFile.readline()
line6 = inFile.readline()
line7 = inFile.readline()
line8 = inFile.readline()

print (line1.split("\n")[0], # split each line and print it --- My proplem in this code!
       line2.split("\n")[0],
       line3.split("\n")[0],
       line4.split("\n")[0],
       line5.split("\n")[0],
       line6.split("\n")[0],
       line7.split("\n")[0],
       line8.split("\n")[0])

a busy cat
(source: gulfup.com)

  • 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-17T17:38:41+00:00Added an answer on June 17, 2026 at 5:38 pm

    If your file isn’t extraordinarily large, you can open the entire contents as one string.

    content = inFile.read()

    Lines of text are split by a special character, \n.
    If you want everything on one line, remove that character.

    oneLine = content.replace('\n', '')

    Here, I’m replacing every \n character with an empty string.

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

Sidebar

Related Questions

There are multiple times in one page where I need to connect and subsequently
I need connect to server git. http://help.github.com/win-set-up-git/ I do everything to the point, 4
Need help writing a script downloads data from google insight using c# this is
I need help thinking up a design where clients connect and communicate with all
I need help in displaying my images from the directory images on my public_html
Need help with below code. I am trying to query from same table and
Multiple customer instances of an application, under a single application. What I need is
I need some help to figure out how to add multiple fields, on a
I need help in writing java code that can connect to a remote UNIX
I need help with displaying images from a MySQL database. What I have is

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.