Thanks,<br>James I will try your suggestion!<br>Robert, what mean with "interactively" is that i would like to create an array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or<br>by reading a file with values etc., and then execute my program with "myprog -m m_i" and thus pass the array "m_i" to my program.<br>
<br>This is just an example. I would like to pass several arrays. My program will be wrapped inside a loop and the arrays are updated <br>in each loop.<br><br>I have never heard of the "argparse" library. Do you think that it would be better to use that in my case?<br>
<br><div class="gmail_quote">Best regards,<br>Johan<br><br>On Tue, Jan 27, 2009 at 7:12 AM, Robert Kern <span dir="ltr"><<a href="mailto:robert.kern@gmail.com" target="_blank">robert.kern@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On 2009-01-27 00:01, Johan Ekh wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thank you James,<br>
but I just can't optparse to accept an array, only integers, floats ans<br>
strings.<br>
<br>
My code looks like this<br>
<br>
from optparse import OptionParser<br>
parser = OptionParser()<br>
parser.add_option('-t', '--dt', action='store', type='float',<br>
dest='dt_i', default=0.1, help='time increment where lsoda saves results')<br>
parser.add_option('-T', '--tstop', action='store', type='float',<br>
dest='tstop_i', default=1.0, help='duration of the solution')<br>
parser.add_option('-m', '--mass_vector', action='store', type='float',<br>
dest='m_i', default=[1.0, 1.0], help='vector with lumped masses')<br>
op, args = parser.parse_args(sys.argv[1:])<br>
<br>
I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse<br>
complains that m_i is not a float.<br>
</blockquote>
<br></div>
Well, yes, because you declared that --mass_vector was type='float'. You will need to subclass OptionParser in order to parse something that is not one of the included types. Yes, it is a bit cumbersome; it's one of the reasons I usually use the third-party argparse library instead. You only need to supply a parsing function rather than subclass.<br>


<br>
I'm afraid I don't really understand what you want when you say that you want to create an array interactively. Can you show me an example command line that you want to parse? Keep in mind that in many shells, ()[] characters are specially handled by the shell and are not convenient for users.<br>


<br>
BTW, I am subscribed to the list. You do not need to Cc me.<div><div></div><div><br>
<br>
-- <br>
Robert Kern<br>
<br>
"I have come to believe that the whole world is an enigma, a harmless enigma<br>
 that is made terrible by our own mad attempt to interpret it as though it had<br>
 an underlying truth."<br>
  -- Umberto Eco<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>