<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/202" rel="nofollow">http://projects.scipy.org/scipy/ticket/202</a> on 2006-05-07 by trac user nodwell@..., assigned to unknown.</em></p>
<p dir="auto">I've made a small modification to import_array.py so that I can parse<br>
a string as if it were a file.  For my own purposes I needed to parse<br>
web form input.</p>
<p dir="auto">For example:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">B = """# comment line<br>
... 3 4 5<br>
... 2 1 5"""<br>
io.read_array(B, datainstring=1)<br>
array([[ 3.,  4.,  5.],<br>
[ 2.,  1.,  5.]])</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">Here is the diff to array_import.py<br>
(there doesn't seem to be a way to attach files to a trac ticket)</p>
<p dir="auto">--- /sw/lib/python2.4/site-packages/scipy/io/array_import.py    2006-03-17 04:43:52.000000000 -0800<br>
+++ array_import.py 2006-05-07 13:11:22.000000000 -0700<br>
@@ -3,7 +3,7 @@</p>
<h1 dir="auto"></h1>
<p dir="auto">"""This module allows for the loading of an array from an ASCII<br>
-Text File<br>
+Text File or a String object.</p>
<p dir="auto">"""</p>
<p dir="auto">@@ -25,6 +25,8 @@</p>
<h1 dir="auto">Written by Travis Oliphant and Trent Oliphant</h1>
<h1 dir="auto">with support from Agilent, Inc.</h1>
<h1 dir="auto"></h1>
<p dir="auto">+# Modified by Eric Nodwell to allow input from a string as well as a file.<br>
+#</p>
<p dir="auto">import os, sys</p>
<p dir="auto">@@ -98,7 +100,7 @@<br>
return file</p>
<p dir="auto">-class ascii_stream:<br>
+class ascii_stream_from_file :<br>
"""Text files with line iteration</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" Ascii_stream instances can be used like normal read-only file objects"><pre class="notranslate"><code class="notranslate"> Ascii_stream instances can be used like normal read-only file objects
</code></pre></div>
<p dir="auto">@@ -108,17 +110,14 @@<br>
Finally, ascii_stream objects accept file names that start with '~' or<br>
'~user' to indicate a home directory(for reading only).</p>
<ul dir="auto">
<li>Constructor: ascii_stream(|fileobject|, |lines|,|comment|),</li>
<li>Constructor: ascii_stream(|fileobject|, |lines|,|comment|, |linesep|),<br>
where |fileobject| is either an open python file object or<br>
the name of the file, |lines| is a sequence of integers<br>
or tuples(indicating ranges) of lines to be read, |comment| is the<br>
comment line identifier """</li>
<li>def <strong>init</strong>(self, fileobject, lines=default, comment="#",</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            linesep='\n'):"><pre class="notranslate"><code class="notranslate">            linesep='\n'):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if not isinstance(comment, types.StringType):"><pre class="notranslate"><code class="notranslate">   if not isinstance(comment, types.StringType):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       raise ValueError, &quot;Comment must be a string.&quot;"><pre class="notranslate"><code class="notranslate">       raise ValueError, "Comment must be a string."
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.linelist = build_numberlist(lines)"><pre class="notranslate"><code class="notranslate">   self.linelist = build_numberlist(lines)
</code></pre></div>
</li>
<li>def <strong>init</strong>(self, fileobject, linelist, comment, linesep):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.linelist = linelist
 self.comment = comment
 self.lencomment = len(comment)
 self.file = get_open_file(fileobject, mode='r')"><pre class="notranslate"><code class="notranslate">   self.linelist = linelist
 self.comment = comment
 self.lencomment = len(comment)
 self.file = get_open_file(fileobject, mode='r')
</code></pre></div>
@@ -183,6 +182,112 @@<br>
self.file.flush()</li>
</ul>
<p dir="auto">+class ascii_stream_from_string :</p>
<ul dir="auto">
<li>"""Line iteration of a string.</li>
<li></li>
<li>Mimics ascii_stream_from_file, even where not strictly necessary</li>
<li>for input from a string.</li>
<li></li>
<li>Ascii_stream instances can be used like normal read-only file objects</li>
<li>(i.e. by calling readline() and readlines()), but can</li>
<li>also be used as sequences of lines in for-loops.</li>
</ul>
<ul dir="auto">
<li></li>
</ul>
<ul dir="auto">
<li>Constructor: ascii_stream(|fileobject|, |lines|,|comment|, |linesep|),</li>
<li>where |fileobject| is either an open python file object or</li>
<li>the name of the file, |lines| is a sequence of integers</li>
<li>or tuples(indicating ranges) of lines to be read, |comment| is the</li>
<li>comment line identifier """</li>
</ul>
<ul dir="auto">
<li></li>
</ul>
<ul dir="auto">
<li>def <strong>init</strong>(self, stringobject, linelist, comment, linesep):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._string = stringobject"><pre class="notranslate"><code class="notranslate">   self._string = stringobject
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.linelist = linelist"><pre class="notranslate"><code class="notranslate">   self.linelist = linelist
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.comment = comment"><pre class="notranslate"><code class="notranslate">   self.comment = comment
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.lencomment = len(comment)"><pre class="notranslate"><code class="notranslate">   self.lencomment = len(comment)
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._lineindex = 0"><pre class="notranslate"><code class="notranslate">   self._lineindex = 0
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if self.linelist[-1] &lt; 0:"><pre class="notranslate"><code class="notranslate">   if self.linelist[-1] &lt; 0:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._linetoget = self.linelist[-1]"><pre class="notranslate"><code class="notranslate">       self._linetoget = self.linelist[-1]
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   else:"><pre class="notranslate"><code class="notranslate">   else:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._linetoget = 0"><pre class="notranslate"><code class="notranslate">       self._linetoget = 0
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._linesplitter = linesep"><pre class="notranslate"><code class="notranslate">   self._linesplitter = linesep
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._buffer = self._string.split(self._linesplitter)"><pre class="notranslate"><code class="notranslate">   self._buffer = self._string.split(self._linesplitter)
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>def readlines(self, sizehint):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   return self._buffer"><pre class="notranslate"><code class="notranslate">   return self._buffer
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>def <strong>getitem</strong>(self, item):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   while 1:"><pre class="notranslate"><code class="notranslate">   while 1:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       line = self.readnextline()"><pre class="notranslate"><code class="notranslate">       line = self.readnextline()
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       if line is None:"><pre class="notranslate"><code class="notranslate">       if line is None:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="           raise IndexError"><pre class="notranslate"><code class="notranslate">           raise IndexError
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       if len(line) &lt; self.lencomment or line[:self.lencomment] != self.comment:"><pre class="notranslate"><code class="notranslate">       if len(line) &lt; self.lencomment or line[:self.lencomment] != self.comment:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="           break"><pre class="notranslate"><code class="notranslate">           break
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   return line"><pre class="notranslate"><code class="notranslate">   return line
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>def readnextline(self):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if self.linelist[self._lineindex] &gt;= 0:"><pre class="notranslate"><code class="notranslate">   if self.linelist[self._lineindex] &gt;= 0:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._linetoget = self.linelist[self._lineindex]"><pre class="notranslate"><code class="notranslate">       self._linetoget = self.linelist[self._lineindex]
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._lineindex += 1"><pre class="notranslate"><code class="notranslate">       self._lineindex += 1
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   else:"><pre class="notranslate"><code class="notranslate">   else:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._linetoget = self._linetoget - self.linelist[self._lineindex]"><pre class="notranslate"><code class="notranslate">       self._linetoget = self._linetoget - self.linelist[self._lineindex]
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if self._linetoget &gt;= len(self._buffer):"><pre class="notranslate"><code class="notranslate">   if self._linetoget &gt;= len(self._buffer):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       return None"><pre class="notranslate"><code class="notranslate">       return None
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   line = self._buffer[self._linetoget]"><pre class="notranslate"><code class="notranslate">   line = self._buffer[self._linetoget]
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   return line"><pre class="notranslate"><code class="notranslate">   return line
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>def close(self):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   pass"><pre class="notranslate"><code class="notranslate">   pass
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>def flush(self):</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   pass"><pre class="notranslate"><code class="notranslate">   pass
</code></pre></div>
<ul dir="auto">
<li></li>
<li></li>
</ul>
+class ascii_stream :</li>
<li>"""Text files or string input with line iteration</li>
</ul>
<ul dir="auto">
<li></li>
</ul>
<ul dir="auto">
<li>Ascii_stream instances can be used like normal read-only file objects</li>
<li>(i.e. by calling readline() and readlines()), but can</li>
<li>also be used as sequences of lines in for-loops.</li>
</ul>
<ul dir="auto">
<li></li>
</ul>
<ul dir="auto">
<li>Ascii_stream objects accept file names that start with '~' or</li>
<li>'~user' to indicate a home directory(for reading only)..  If</li>
<li>|datainstring| is true, then instead of reading lines from a file,</li>
<li>|fileobject| is taken as a string from which lines are read.</li>
</ul>
<ul dir="auto">
<li></li>
</ul>
<ul dir="auto">
<li>
<p dir="auto">Constructor: ascii_stream(|fileobject|, |lines|,|comment|,</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="              |linesep|, |datainstring|),"><pre class="notranslate"><code class="notranslate">              |linesep|, |datainstring|),
</code></pre></div>
</li>
<li>
<p dir="auto">where |fileobject| is either an open python file object or</p>
</li>
<li>
<p dir="auto">the name of the file, |lines| is a sequence of integers</p>
</li>
<li>
<p dir="auto">or tuples(indicating ranges) of lines to be read, |comment| is the</p>
</li>
<li>
<p dir="auto">comment line identifier """</p>
</li>
<li></li>
<li>
<p dir="auto">def <strong>init</strong>(self, fileobject, lines=default, comment="#",</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            linesep='\n', datainstring=0):"><pre class="notranslate"><code class="notranslate">            linesep='\n', datainstring=0):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if not isinstance(comment, types.StringType):"><pre class="notranslate"><code class="notranslate">   if not isinstance(comment, types.StringType):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       raise ValueError, &quot;Comment must be a string.&quot;"><pre class="notranslate"><code class="notranslate">       raise ValueError, "Comment must be a string."
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.linelist = build_numberlist(lines)"><pre class="notranslate"><code class="notranslate">   self.linelist = build_numberlist(lines)
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.comment = comment"><pre class="notranslate"><code class="notranslate">   self.comment = comment
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self.lencomment = len(comment)"><pre class="notranslate"><code class="notranslate">   self.lencomment = len(comment)
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   if datainstring:"><pre class="notranslate"><code class="notranslate">   if datainstring:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._stream = ascii_stream_from_string (fileobject, self.linelist,"><pre class="notranslate"><code class="notranslate">       self._stream = ascii_stream_from_string (fileobject, self.linelist,
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="           comment, linesep)"><pre class="notranslate"><code class="notranslate">           comment, linesep)
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   else:"><pre class="notranslate"><code class="notranslate">   else:
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="       self._stream = ascii_stream_from_file (fileobject, self.linelist,"><pre class="notranslate"><code class="notranslate">       self._stream = ascii_stream_from_file (fileobject, self.linelist,
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="           comment, linesep)"><pre class="notranslate"><code class="notranslate">           comment, linesep)
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._buffer = self._stream._buffer"><pre class="notranslate"><code class="notranslate">   self._buffer = self._stream._buffer
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>
<p dir="auto">def readlines(self, sizehint):</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   return self._stream.readlines(sizehint)"><pre class="notranslate"><code class="notranslate">   return self._stream.readlines(sizehint)
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>
<p dir="auto">def <strong>getitem</strong>(self, item):</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   return self._stream.__getitem__(item)"><pre class="notranslate"><code class="notranslate">   return self._stream.__getitem__(item)
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>
<p dir="auto">def close(self):</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._stream.close()"><pre class="notranslate"><code class="notranslate">   self._stream.close()
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
</li>
<li>
<p dir="auto">def flush(self):</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   self._stream.flush()"><pre class="notranslate"><code class="notranslate">   self._stream.flush()
</code></pre></div>
<ul dir="auto">
<li></li>
<li></li>
</ul>
<p dir="auto">def move_past_spaces(firstline):<br>
ind = 0<br>
firstline = firstline.lstrip()<br>
@@ -295,13 +400,14 @@</p>
<p dir="auto">def read_array(fileobject, separator=default, columns=default, comment="#",<br>
lines=default, atype=numpy.Float, linesep='\n',</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          rowsize=10000, missing=0):"><pre class="notranslate"><code class="notranslate">          rowsize=10000, missing=0):
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          rowsize=10000, missing=0, datainstring=0):"><pre class="notranslate"><code class="notranslate">          rowsize=10000, missing=0, datainstring=0):
</code></pre></div>
<p dir="auto">"""Return an array or arrays from ascii_formatted data in |fileobject|.</p>
<p dir="auto">Inputs:</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" fileobject -- An open file object or a string for a valid filename."><pre class="notranslate"><code class="notranslate"> fileobject -- An open file object or a string for a valid filename.
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="               The string can be prepended by &quot;~/&quot; or &quot;~&lt;name&gt;/&quot; to"><pre class="notranslate"><code class="notranslate">               The string can be prepended by "~/" or "~&lt;name&gt;/" to
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" fileobject -- An open file object or a string for a valid filename"><pre class="notranslate"><code class="notranslate"> fileobject -- An open file object or a string for a valid filename
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="               or a string to be parsed (if datainstring is nonzero)."><pre class="notranslate"><code class="notranslate">               or a string to be parsed (if datainstring is nonzero).
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="               A file name can be prepended by &quot;~/&quot; or &quot;~&lt;name&gt;/&quot; to
             read a file from the home directory."><pre class="notranslate"><code class="notranslate">               A file name can be prepended by "~/" or "~&lt;name&gt;/" to
             read a file from the home directory.
</code></pre></div>
<p dir="auto">separator -- a string or a tuple of strings to indicate the column<br>
separators.  If the length of the string tuple is less<br>
@@ -330,6 +436,8 @@<br>
copying the last entry.<br>
rowsize -- the allocation row size (array grows by this amount as<br>
data is read in).</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" datainstring -- if nonzero, interpet fileobject as containing the"><pre class="notranslate"><code class="notranslate"> datainstring -- if nonzero, interpet fileobject as containing the
</code></pre></div>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          data to be read in."><pre class="notranslate"><code class="notranslate">          data to be read in.
</code></pre></div>
<p dir="auto">Output -- the 1 or 2d array, or a tuple of output arrays of different<br>
types, sorted in order of the first column to be placed<br>
@@ -344,7 +452,8 @@<br>
else:<br>
sep = tuple(separator)</p>
<h1 dir="auto">Create ascii_object from |fileobject| argument.</h1>
</li>
<li>
<p dir="auto">ascii_object = ascii_stream(fileobject, lines=lines, comment=comment, linesep=linesep)</p>
</li>
<li>
<p dir="auto">ascii_object = ascii_stream(fileobject, lines=lines, comment=comment,</p>
</li>
<li>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   linesep=linesep, datainstring=datainstring)"><pre class="notranslate"><code class="notranslate">   linesep=linesep, datainstring=datainstring)
</code></pre></div>
<p dir="auto">columns, atype = convert_to_equal_lists(columns, atype)<br>
numout = len(atype)</p>
<h1 dir="auto">Get the number of columns to read and expand the columns argument</h1>
</li>
</ul>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1688" rel="nofollow">http://projects.scipy.org/scipy/ticket/1688</a> on 2012-07-05 by trac user jokahn, assigned to unknown.</em></p>
<p dir="auto">binomial and scipy.stats.binom are not defined for n=0, raising a value error.<br>
For example<br>
[[BR]]<br>
<code class="notranslate">binomial(0, .3)</code><br>
[[BR]]<br>
or<br>
[[BR]]<br>
<code class="notranslate">scipy.stats.binom.rvs(arange(5),.3)</code><br>
[[BR]]<br>
will fail.</p>
<p dir="auto">The binomial distribution is perfectly well-defined in this case: it is merely the Dirac at zero. Therefore a function implementing this random variable should not fail in this case.</p>
<p dir="auto">Add to that the fact that a typical use of the function would be thinning data on many entries, where some might be zero, and it's also a practical concern.</p>