Re: [Tutor] creating a regularly placed fields in a line

2012-04-26 Thread Wayne Werner
On Wed, 25 Apr 2012, Prasad, Ramit wrote: Useful to know both though, since lots of people swear by % substitution. And % formatting is slightly faster - if you end out doing tons of formatting and you find your script isn't fast enough, it's worth taking a look there. -Wayne _

Re: [Tutor] creating a regularly placed fields in a line

2012-04-25 Thread Alan Gauld
On 25/04/12 16:17, Bala subramanian wrote: placed depending up on the size of the field. I am thinking to fix the size of each field. with open('tmp') as tp: for line in tp: ... bond.write(' %s\t%s\t%s\t%s\t%s\n' % (p1,p2,p3,p4,new) ) Add your widths to the format string:

Re: [Tutor] creating a regularly placed fields in a line

2012-04-25 Thread Prasad, Ramit
> > > > Not really sure how to do the equivalent with % substitution. > > > > See > http://docs.python.org/library/stdtypes.html#string-formatting-operations > > Mark Lawrence. Thanks Mark. Based on that, I find .format more intuitive (especially for alignment) than % substitution. Useful to k

Re: [Tutor] creating a regularly placed fields in a line

2012-04-25 Thread Mark Lawrence
On 25/04/2012 16:57, Prasad, Ramit wrote: Not really sure how to do the equivalent with % substitution. Ramit See http://docs.python.org/library/stdtypes.html#string-formatting-operations -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@

Re: [Tutor] creating a regularly placed fields in a line

2012-04-25 Thread Prasad, Ramit
> I wrote a small piece of code (given below). The aim is to take each line > in a file, split the fields, replace the first four fields and then write > the new lines in a output file. The input and output are given in the > attached file. The output contains fields which are irregularly placed >