optparse with numpy.array?
Robert Kern
robert.kern at gmail.com
Mon Jan 26 19:00:16 EST 2009
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
More information about the Python-list
mailing list