473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4871
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
3537
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
2367
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
660
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
1868
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
2309
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
2836
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
4942
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
1254
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
1574
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
2441
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
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.