<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Jython: read array from a text file' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Jython: read array from a text file' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 24 May 2012 00:24:43 -0700</pubDate>
    <lastBuildDate>Thu, 24 May 2012 00:24:43 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Jython: read array from a text file</title>
      <link>http://www.programmersheaven.com/mb/python/418012/418012/jython-read-array-from-a-text-file/</link>
      <description>Hi, I have a question about reading float data from a text file and hope somebody can give me some ideas, code is strongly appreciated!&lt;br /&gt;
&lt;br /&gt;
I wrote some float numbers in a text file as below:&lt;br /&gt;
  0.1550000     ,   863500.0     ,   344600.0     ,  1.5999969E-02 ,&lt;br /&gt;
  0.1600000     ,   863500.0     ,   344600.0     ,  3.1999987E-02 ,&lt;br /&gt;
  0.1650000     ,   863500.0     ,   344600.0     ,  4.7999956E-02 ,&lt;br /&gt;
  0.1700000     ,   863500.0     ,   344600.0     ,  6.3999951E-02 ,&lt;br /&gt;
  ....&lt;br /&gt;
&lt;br /&gt;
Now I want to read these numbers from this text file into an array to use later in the code. I hope the array will look like: &lt;br /&gt;
array=[0.1550000,863500.0,344600.0,1.5999969E-02,0.1600000,863500.0,344600.0,  3.1999987E-02, .....]&lt;br /&gt;
&lt;br /&gt;
My CODE is:&lt;br /&gt;
def main(args):&lt;br /&gt;
&lt;br /&gt;
  inf=open("a.txt", 'r')&lt;br /&gt;
  &lt;br /&gt;
  z = []&lt;br /&gt;
  z = inf.readlines()&lt;br /&gt;
  print z&lt;br /&gt;
&lt;br /&gt;
result: z is a big string, not individual float numbers&lt;br /&gt;
--------------------------------------------&lt;br /&gt;
If I change my code to:&lt;br /&gt;
def main(args):&lt;br /&gt;
&lt;br /&gt;
  inf=open("a.txt", 'r')&lt;br /&gt;
  &lt;br /&gt;
  z = []&lt;br /&gt;
  for line in inf.readlines():&lt;br /&gt;
      for number in line.strip('\n'):&lt;br /&gt;
		z.append(number)&lt;br /&gt;
  print z&lt;br /&gt;
&lt;br /&gt;
result is like: [------  '2', '.', '9', '5', '0', '0', '0', '0', ' ', ' ', ' ', ' ', ' ', ',', ' ', ' ', ' ', '8', '9', '2', '0', '5', '0', '.', '0', ' ', ' ', '-------]&lt;br /&gt;
&lt;br /&gt;
Please help me... Thanks in advance! It's really hard to google good help of Jython!&lt;br /&gt;
&lt;br /&gt;
Cheers!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/418012/418012/jython-read-array-from-a-text-file/</guid>
      <pubDate>Tue, 20 Jul 2010 14:47:01 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
