[GRASS-dev] G_parser and python

Hi,
i am try to use option and flag in python script in this code:
     1. import sys
     2. sys.path.append("/usr/local/grass-6.4.0svn/etc/python")
     3. from grass.lib import grass as gl6
     4. import random
     5.
     6. gl6.G_gisinit('')
     7.
     8. mapset=gl6.G_mapset()
     9.
    10. opt=gl6.Option()
    11. opt=gl6.G_define_option()
    12. opt.key='debug'
    13. opt.description='Option test'
    14. opt.type=gl6.TYPE_STRING
    15. opt.required=gl6.YES
    16.
    17.
    18. if (gl6.G_parser(0,gl6.sys.argv)):
    19. exit()
    20.
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 **'

___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com

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@gclements.plus.com>

On Fri, Jun 5, 2009 at 3:00 PM, Glynn Clements<glynn@gclements.plus.com> wrote:
...

This should be:

 18\. if \(gl6\.G\_parser\(len\(sys\.argv\),sys\.argv\)\):

However, there isn't a typemap for char**.

...

I've added a typemap for char** in r37741 (trunk):

   http://trac.osgeo.org/grass/changeset/37741

Backported to 6.5.svn and 6.4.svn.

Markus