Re: print "%s"

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

    Re: print "%s"

    On 18Aug2008 11:58, Beema Shafreen <beema.shafreen @gmail.comwrote :
    | In my script i have to print a series of string , so
    |
    | print "%s\t%s\t%s\t%s \t%s\t%s\t" %("a","v","t"," R","s","f")
    |
    | I need to know instead of typing so many %s can i write %6s in python, as
    | we do in C progm.

    I hate to tell you this, but "%6s" in C does NOT print 6 strings. It
    prints 1 string, right justified, in no less that 6 characters.
    C is just like Python in this example.

    | What are the other options .

    Write a small loop to iterate over the strings. Print a tab before each
    string except the first.

    Cheers,
    --
    Cameron Simpson <cs@zip.com.auD oD#743


    You see, wire telegraph is a kind of a very, very long cat. You pull his tail
    in New York and his head is meowing in Los Angeles. Do you understand this?
    And radio operates exactly the same way: you send signals here, they receive
    them there. The only difference is that there is no cat.
    - Albert Einstein, when asked to describe radio
  • Bruno Desthuilliers

    #2
    Re: print &quot;%s&quo t;

    Cameron Simpson a écrit :
    On 18Aug2008 11:58, Beema Shafreen <beema.shafreen @gmail.comwrote :
    | In my script i have to print a series of string , so
    |
    | print "%s\t%s\t%s\t%s \t%s\t%s\t" %("a","v","t"," R","s","f")
    |
    | I need to know instead of typing so many %s can i write %6s in python, as
    | we do in C progm.
    >
    I hate to tell you this, but "%6s" in C does NOT print 6 strings. It
    prints 1 string, right justified, in no less that 6 characters.
    C is just like Python in this example.
    >
    | What are the other options .
    >
    Write a small loop to iterate over the strings. Print a tab before each
    string except the first.
    Or use the str.join method:

    print "\t".join(list( "avtRsf"))

    Comment

    • Maric Michaud

      #3
      Re: print &quot;%s&quo t;

      Le Monday 18 August 2008 09:27:33 Bruno Desthuilliers, vous avez écrit :
      Cameron Simpson a écrit :
      On 18Aug2008 11:58, Beema Shafreen <beema.shafreen @gmail.comwrote :
      | In my script i have to print a series of string , so
      |
      | print "%s\t%s\t%s\t%s \t%s\t%s\t" %("a","v","t"," R","s","f")
      |
      | I need to know instead of typing so many %s can i write %6s in python,
      | as we do in C progm.

      I hate to tell you this, but "%6s" in C does NOT print 6 strings. It
      prints 1 string, right justified, in no less that 6 characters.
      C is just like Python in this example.

      | What are the other options .

      Write a small loop to iterate over the strings. Print a tab before each
      string except the first.
      >
      Or use the str.join method:
      >
      print "\t".join(list( "avtRsf"))
      >
      Not related to OP's question, but why one would want to convert a string toa
      list to make it iterable ?

      >>>[3]: print '\t'.join('azer ty')
      a z e r t y




      --
      _____________

      Maric Michaud

      Comment

      • gundlach

        #4
        Re: print &quot;%s&quo t;

        The string.join() approach is better for your purpose, but FYI you can
        multiply a string to repeat it:

        In [2]: "%s\t" * 6
        Out[2]: '%s\t%s\t%s\t%s \t%s\t%s\t'

        - Michael

        On Aug 18, 3:27 am, Bruno Desthuilliers <bruno.
        42.desthuilli.. .@websiteburo.i nvalidwrote:
        Cameron Simpson a écrit :
        >
        >
        >
        On 18Aug2008 11:58, Beema Shafreen <beema.shafr... @gmail.comwrote :
        | In my script i have to print a series of string , so
        |
        | print "%s\t%s\t%s\t%s \t%s\t%s\t" %("a","v","t"," R","s","f")
        |
        | I need to know instead of typing so many %s  can i write %6s in python, as
        | we do in C progm.
        >
        I hate to tell you this, but "%6s" in C does NOT print 6 strings. It
        prints 1 string, right justified, in no less that 6 characters.
        C is just like Python in this example.
        >
        | What are the other options .
        >
        Write a small loop to iterate over the strings. Print a tab before each
        string except the first.
        >
        Or use the str.join method:
        >
        print "\t".join(list( "avtRsf"))

        Comment

        Working...