473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Re: print "%s"

On 18Aug2008 11:58, Beema Shafreen <be************@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.auDoD#743
http://www.cskk.ezoshosting.com/cs/

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
Aug 18 '08 #1
3 4859
Cameron Simpson a écrit :
On 18Aug2008 11:58, Beema Shafreen <be************@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"))

Aug 18 '08 #2
Le Monday 18 August 2008 09:27:33 Bruno Desthuilliers, vous avez écrit*:
Cameron Simpson a écrit :
On 18Aug2008 11:58, Beema Shafreen <be************@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('azerty')
a z e r t y
--
http://mail.python.org/mailman/listinfo/python-list


--
_____________

Maric Michaud
Aug 18 '08 #3
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.invalidwrote:
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"))
Aug 18 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Albert Wagner | last post by:
I have just had a problem that I cannot find any reference to in any docs. Admittedly, I am a JavaScript newbie, but this sure seems like a bug or an "undocumented feature" in Opera 7.11. I have...
17
by: Geoff Cox | last post by:
Hello, I am trying to have 1. web pages in large font 2. web pages with smaller font for printing I am using <link rel="stylesheet" media="print" type="text/css"
16
by: John Baker | last post by:
HI; I feel like a fool..I put CUTE FTP in my last request for help --it should have been CUTE PDF! I have FTP on my mind because I have been working on a web based application, and somehow my...
5
by: Paul Sullivan | last post by:
We are a state agency that views protected medical information via our intranet. The screens even have privacy shields. Alarmingly, uses can "Print" and "Save As" which destroys the protection of...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
2
by: kbperry | last post by:
Hi all, I am getting an error message when trying to use the P4 print command via the python api for perforce. Anytime that I run p4c.run("print","-q", eachFile), I keep getting an error...
1
by: Appu | last post by:
How to Check in the window print dialog box whether we clicked either "print" or "cancel". while clicking a button i call wnidow.print() to pop up the windows PRint Dialog box. I want to check...
0
by: moti far | last post by:
hi, i use stylesheet to design the plot of the print page. The page works with https(ssl) protocol. this my code: <html> <head>
10
by: Prisoner at War | last post by:
Hi, your friendly neighborhood n00b here, just wondering why on earth the Py3K folks want to mess with a simple thing like the "print" "command" (is that what it's called, a command?), turning it...
2
by: sixtyfootersdude | last post by:
Good Morning! I am just starting to learn perl and I am somewhat mistifide about when I should do: print("@input"); and when I should do: print(@input)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.