[GRASS-dev] G_parser and python
Glynn Clements
glynn at gclements.plus.com
Fri Jun 5 09:00:07 EDT 2009
Danho Fursy Rodelec Neuba wrote:
> i am try to use option and flag in python script in this code:
> 10. opt=gl6.Option()
This is unnecessary.
> 18. if (gl6.G_parser(0,gl6.sys.argv)):
This should be:
18. if (gl6.G_parser(len(sys.argv),sys.argv)):
However, there isn't a typemap for char**.
> and i got the following error:
> Traceback (most recent call last):
> File "grass2.py", line 18, in <module>
> if (gl6.G_parser(0,gl6.sys.argv)):
> TypeError: in method 'G_parser', argument 2 of type 'char **'
I've added a typemap for char** in r37741 (trunk):
http://trac.osgeo.org/grass/changeset/37741
Note that the SWIG bindings are still at an early stage. There are
probably many typemaps and helper functions which will need to be
added.
Actually, I'm not convinced that we won't eventually run into one of
SWIGs limitations and be forced to abandon it. SWIG tends to fail
rather hard (i.e. with no realistic workaround) if your code wasn't
intended as a language extension from the outset.
Python's ctypes library is far more flexible, but it means having to
manually write a wrapper for each function and type which you wish to
use.
You can use both SWIG and ctypes in the same program, but you can't
pass values between them (and you can't construct SWIG-compatible
values from Python if no C wrapper exists for them).
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list