optparse with numpy.array?
ekh.johan at gmail.com
Tue Jan 27 06:45:59 CET 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!
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?
> 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
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> that is made terrible by our own mad attempt to interpret it as though it
> an underlying truth."
> -- Umberto Eco
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list