optparse with numpy.array?

Johan Ekh ekh.johan at gmail.com
Tue Jan 27 00:45:59 EST 2009


Thank you Robert,
but what if I just want to create an array interactively, e.g. like m  =
array([1.0, 2.0, 3.0]), and pass it
to my program? I tried extending optparse with a new type as explained in
the link you gave me
but I was not able to get it to work. Is it really neccessary follow that
route just to pass an array?
Lot's of people must have done this before!

Best regards,
Johan

On Tue, Jan 27, 2009 at 1:00 AM, Robert Kern <robert.kern at gmail.com> wrote:

> On 2009-01-26 17:44, Johan Ekh wrote:
>
>> Hi all,
>> I'm trying to use optparse to process command line parameters given to
>> my program.
>> It works as I expect for the types supported by optparse, i.e. int,
>> float, string etc. but how can I
>> pass a numpy.array or a list to my program?
>>
>
> http://docs.python.org/library/optparse#optparse-extending-optparse
>
> Figure out the text format you want your users to type the value on the
> command line, write a function that will take that text and convert it to an
> array or list, then customize OptionParser to use that parser as given in
> the link above. Keep in mind that your user probably won't want to need to
> use whitespace or any kind of brackets. Commas are nice, though.
>
> You may also want to consider taking a filename and parsing that file
> instead.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma
>  that is made terrible by our own mad attempt to interpret it as though it
> had
>  an underlying truth."
>  -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090127/d23785dd/attachment-0001.html>


More information about the Python-list mailing list