Query about doing fortran-esque repeat formatting
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 |
Newsgroups: comp.lang.python
From: Rob Briggs <rdbri...@mun.ca>
Date: Sun, 08 Nov 2009 11:26:18 -0330
Local: Sun 8 Nov 2009 14:56
Subject: Query about doing fortran-esque repeat formatting
Hello, Is there a way to do a repeat formatting command like in Fortran? Rather that doing this: print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) Something like this: print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) regards, Rob
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Mensanator <mensana...@aol.com>
Date: Sun, 8 Nov 2009 08:08:55 -0800 (PST)
Local: Sun 8 Nov 2009 16:08
Subject: Re: Query about doing fortran-esque repeat formatting
On Nov 8, 8:56 am, Rob Briggs <rdbri...@mun.ca> wrote:
> Hello, > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > tmp[i][8], tmp[i][9]) > Something like this: > print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], > tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) >>> s = '%s ' + ' %-5.4f' * 7 >>> s
'%s %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f' >>> print s % ('s',1,2,3,4,5,6,7)
s 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Novocastrian_Nomad <gregory.j.ba...@gmail.com>
Date: Sun, 8 Nov 2009 16:56:40 -0800 (PST)
Local: Mon 9 Nov 2009 00:56
Subject: Re: Query about doing fortran-esque repeat formatting
How about: print ('%s ' + '%-5.4f ' * 7) % ('text',1,2,3,4,5,6,7)
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Glenn Hutchings <zond...@googlemail.com>
Date: Mon, 9 Nov 2009 12:05:54 +0000 (UTC)
Local: Mon 9 Nov 2009 12:05
Subject: Re: Query about doing fortran-esque repeat formatting
Rob Briggs <rdbriggs <at> mun.ca> writes: > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > tmp[i][8], tmp[i][9])
There certainly is. You can use python's string concatenation and repeat operators: print "%s" + " %-5.3f" * 7 % <stuff> Glenn
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Rob Briggs <rdbri...@mun.ca>
Date: Mon, 09 Nov 2009 11:23:23 -0330
Local: Mon 9 Nov 2009 14:53
Subject: Re: Query about doing fortran-esque repeat formatting
Thanks to the chaps who answered, I knew there would be an efficient answer to this. regards, Rob
On Mon, 2009-11-09 at 13:31 +0100, Jean-Michel Pichavant wrote: > Glenn Hutchings wrote: > > Rob Briggs <rdbriggs <at> mun.ca> writes: > > > Is there a way to do a repeat formatting command like in Fortran? Rather > > > that doing this: > > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > > > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > > > tmp[i][8], tmp[i][9]) > > There certainly is. You can use python's string concatenation > > and repeat operators: > > print "%s" + " %-5.3f" * 7 % <stuff> > > Glenn > data = tuple(parmName[i]) + tuple(tmp[i]) > print "%s" + " %-5.3f" * len(tmp[i]) % data > That should do the trick. > JM
You must Sign in before you can post messages.
You do not have the permission required to post.
|
|
|