After a little further digging, I now realise that Jython reflectively
determines whether a method supports keyword arguments by checking
whether it has a PyObject[] and String[] for parameters.
Oh well, that's something else I have learned! I am getting there,
gradually :)
Paul Drummond wrote:
> Hi Guys,
>
> I have been spending what little spare time I have looking at the csv
> module. I'm afraid I haven't got very far yet as I am currently smack
> bang in the middle of a very steep learning curve! I am making progress
> however and am still as keen as ever!
>
> Currently, I am trying to understand the correct way to parse the
> arguments for csv.reader(). The method's definition from the python
> library docs is:
>
> reader(csvfile[, dialect='excel'[, fmtparam]])
>
> As csvfile is mandatory I thought it would be okay to specify it
> explicitly in my method signature, then use optional arguments for the
> rest. With a little help from the Wiki FAQ I ended up with this:
>
> public static PyObject reader(PyObject iterableObject, PyObject[] args,
> String[] keywords) {
> }
>
> But here is where I get confused because now Jython *EXPECTS* 3
> arguments which is not how Python behaves:
>
> >>> import csv
> >>> csv.reader()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: expected at least 1 arguments, got 0
>
> jython:
> >>> import csv
> >>> csv.reader()
> Traceback (innermost last):
> File "<console>", line 1, in ?
> TypeError: reader(): expected 3 args; got 0
> >>>
>
> So to make csv.reader() behave the same as python, I'd need to pass an
> array of PyObjects into reader() then use ArgParser and do my own type
> checking and error handling:
>
> public static PyObject reader(PyObject[] args) {
> //Use ArgParser and my own error handling to throw if there isn't
> //at least one argument + other checks.
> }
>
> I guess it's easier to explicitly specify arguments when the module
> hides behind a python wrapper then you already know the number of
> arguments the wrapper uses. I can't do this for csv as the reader()
> method is exposed directly through the csv.py wrapper so it must support
> dynamic arguments.
>
> Does all of this make sense or am I getting it completely wrong?
>
> Cheers,
> Paul.
>
>
>
>
>
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Jython-dev mailing list
> Jython-dev@...
> https://lists.sourceforge.net/lists/listinfo/jython-dev
>
|