concat next line with previous

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s99999999s2003@yahoo.com

    #1

    concat next line with previous

    hi
    what is the python way to concat 2 lines eg

    line 1 with some text
    line 2 with some text

    i want to bring line 2 up , such that i get one whole string.

    line 1 with some text line 2 with some text

  • Sybren Stuvel

    #2
    Re: concat next line with previous

    s99999999s2003@ yahoo.com enlightened us with:
    hi
    what is the python way to concat 2 lines eg
    concated = line1 + line2

    Sybren
    --
    Sybren Stüvel
    Stüvel IT - http://www.stuvel.eu/

    Comment

    • Simon Brunning

      #3
      Re: concat next line with previous

      On 26 Sep 2006 03:16:25 -0700, s99999999s2003@ yahoo.com
      <s99999999s2003 @yahoo.comwrote :
      what is the python way to concat 2 lines eg
      >
      line 1 with some text
      line 2 with some text
      >
      i want to bring line 2 up , such that i get one whole string.
      >
      line 1 with some text line 2 with some text
      line1 = "line 1 with some text"
      line2 = "line 2 with some text"

      # Simplest way:

      line3 = line1 + line2

      # More general - joining a sequence of strings, with delimiter

      lines = [line1, line2]
      line3 = ", ".join(line s)

      --
      Cheers,
      Simon B,
      simon@brunningo nline.net,

      Comment

      • tobiah

        #4
        Re: concat next line with previous

        s99999999s2003@ yahoo.com wrote:
        hi
        what is the python way to concat 2 lines eg
        >
        line 1 with some text
        line 2 with some text
        >
        i want to bring line 2 up , such that i get one whole string.
        >
        line 1 with some text line 2 with some text
        >
        assuming that the 'lines' have newlines at the end,
        maybe:

        ' '.join(line1[:-1], line2)

        or

        ' '.join(line.rep lace('\n', ''), line2)

        Which covers the case of no newline at the end as well.


        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • Ben Finney

          #5
          Re: concat next line with previous

          tobiah <toby@tobiah.or gwrites:
          assuming that the 'lines' have newlines at the end,
          No need to assume; tell the string what you want.

          ' '.join(line1.rs trip('\n'), line2)

          --
          \ "Nothing is so common as to imitate one's enemies, and to use |
          `\ their weapons." -- Voltaire, _Dictionnaire Philosophique_ |
          _o__) |
          Ben Finney

          Comment

          Working...