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.k...@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
>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to