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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:53:03+00:00 2026-06-09T06:53:03+00:00

my_string = This is my first line, this is my second line, and… …this

  • 0
my_string = """This is my first line,
this is my second line, and...

...this is my fourth line!"""

How can I store the first line of that (This is my first line,) into a separate string? I attempted to use .readline() from another similar question, however I get this error:

AttributeError: 'str' object has no attribute 'readline'

  • 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-09T06:53:05+00:00Added an answer on June 9, 2026 at 6:53 am

    Use str.partition() to split the string on a newline, and grab the first item from the result:

    my_string.partition('\n')[0]
    

    This is the most efficient method if you only need to split a string in a single location. You could use str.split() too:

    my_string.split('\n', 1)[0]
    

    You do then need to tell the method to only split once, on the first newline, as we discard the rest.

    Or you could use the .splitlines() method:

    my_string.splitlines()[0]
    

    but this has to create separate strings for every newline in the input string so is not nearly as efficient.

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

Sidebar

Related Questions

Say this is my string $string = 'product[0][1][0]'; How could I use that string
Right now i have this ***FIRST***1DESIGNRESULTSM25Fe415 ***Second***Fe415 ***Third***1500.0mm ***Fourth***300.0mmX600.0mmCOVER:40.0mm ***Fifth***15ENDJOINT:13SHORTCOLUMN ***Sixth***5472.00Sq.mm.REQD.CONCRETEAREA:174528.00Sq.mm ***Seventh***12-25dia.(3.27%,5890.49Sq.mm.)(Equallydistributed) ***Eighth***8mm ***Ninth***300mmc/c
My string like this: { key: value’s, key2: value } I use json_decode() PHP
My string looks like this $string_value = /hello/world/this/feels/great/ how can I trim world and
my string is: [{property:surname,direction:ASC}] can I get GSON to deserialise this, without adding to
can you help me with this.. what i'm trying to accomplish is that when
my txt file contains this: john 1.0 Novice ed 3.0 Wiz first line is
I'm using the regex string below to look for words that in this case
I have a text file that contains the following data. The first line is
I'm trying to use a string from my backing bean which may contain line

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.