Converting tuple to String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Byte

    #1

    Converting tuple to String

    Is their a command to convert a tuple to string? e.g.

    xyz = "Hello", "There"
    print xyz

    Is their any way of getting print to see xyz as being one string i.e.
    "Hello There" rather than "Hello" and "There", despite "Hello" and
    "There" being, in reality, seperate?

    Thanks in advance,
    -- /usr/bin/byte

  • Stefan Lang

    #2
    Re: Converting tuple to String

    On Sunday 30 April 2006 17:32, Byte wrote:[color=blue]
    > Is their a command to convert a tuple to string? e.g.
    >
    > xyz = "Hello", "There"
    > print xyz
    >
    > Is their any way of getting print to see xyz as being one string
    > i.e. "Hello There" rather than "Hello" and "There", despite "Hello"
    > and "There" being, in reality, seperate?[/color]

    Use the "join" method of strings:

    print ' '.join(xyz)

    --
    Stefan

    Comment

    • Daniel Nogradi

      #3
      Re: Converting tuple to String

      > Is their a command to convert a tuple to string? e.g.[color=blue]
      >
      > xyz = "Hello", "There"
      > print xyz
      >
      > Is their any way of getting print to see xyz as being one string i.e.
      > "Hello There" rather than "Hello" and "There", despite "Hello" and
      > "There" being, in reality, seperate?[/color]

      Try

      one_big_string = ''.join( xyz )
      print one_big_string

      Hope this helps.

      Comment

      • Byte

        #4
        Re: Converting tuple to String

        Great, that works thanks

        -- /usr/bin/byte

        Comment

        Working...