[Tutor] Appending an extra column in a data file
Sayan Chatterjee
sayanchatterjee at gmail.com
Wed Apr 10 20:48:54 CEST 2013
Thanks Oscar figured it out...:)
On 11 April 2013 00:17, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> On 10 April 2013 17:58, Sayan Chatterjee <sayanchatterjee at gmail.com>
> wrote:
> > Thank Andre for your prompt answer.
> >
> > I'll figure out the plotting issue once the dat files are made. So it's
> the
> > primary concern.
> > For an example I am attaching a dat file herewith. The two columns here
> are
> > 2 numpy arrays.I want to add a third column, to be precise, I want to
> print
> > a parameter value on the third column of the file.
>
> The file you attached is a space-delimited text file. If you want to
> add a third column with the value '1.0' on every row you can just do:
>
> with open('old.dat') as fin, open('new.dat', 'w') as fout:
> for line in fin:
> fout.write(line[:-1] + ' 1.0\n')
>
>
> Oscar
>
--
--------------------------------------------------------------------------
*Sayan Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com
Volunteer , Padakshep
www.padakshep.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130411/ccb92a4b/attachment.html>
More information about the Tutor
mailing list