Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24511
| From | Cousin Stanley <cousinstanley@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: [newbie] problem with data (different behaviour between batch and interactive use) |
| Date | 2012-06-27 13:23 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <jsf1gl$gld$1@dont-email.me> (permalink) |
| References | <aec77bb0-7d2f-43f7-a556-3a59ad016112@googlegroups.com> |
Jean Dupont wrote:
> I have some data which is presented
> in the following format to me :
>
> +3.874693E-01,+9.999889E-03,+9.910000E+37,+1.876595E+04,+3.994000E+04
>
> I'm only interested in the first two fields i.e.
>
> +3.874693E-01,+9.999889E-03
> ....
The following program will read lines
of comma-separated data from a text file
and add each line as a row in a list of lists ....
The first two items in each row
could be accessed by their indexes ....
# --------------------------------------------------
#!/usr/bin/env python
fsource = open( 'edata.txt' )
ltarget = [ ]
for this_line in fsource :
this_list = this_line.strip().split( ',' )
that_list = [ float( x ) for x in this_list ]
ltarget.append( that_list )
for this_row in ltarget :
print ' %e' % this_row[ 0 ]
print ' %e' % this_row[ 1 ]
print
fsource.close()
# -----------------------------------------------------
#
# edata.txt
+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04
1e01,2e02,3e03,4e04,5e05
5e-05,4e-04,3e-03,2e-02,1e-01
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[newbie] problem with data (different behaviour between batch and interactive use) Jean Dupont <jeandupont115@gmail.com> - 2012-06-27 05:24 -0700 Re: [newbie] problem with data (different behaviour between batch and interactive use) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-06-27 15:46 +0300 Re: [newbie] problem with data (different behaviour between batch and interactive use) Cousin Stanley <cousinstanley@gmail.com> - 2012-06-27 13:23 +0000 Re: [newbie] problem with data (different behaviour between batch and interactive use) Justin Barber <barber.justin@gmail.com> - 2012-06-27 07:09 -0700
csiph-web