catch argc-argv
Duncan Booth
duncan.booth at invalid.invalid
Mon Jun 20 06:53:30 EDT 2005
John Machin wrote:
>> So, my question is: does the Python API containe fonctions like
>> 'get_argc()' and 'get_argv()' ?
>>
>
> If you can't see them in the documentation, they aren't there. If they
> aren't there, that's probably for a good reason -- no demand, no use
> case.
>
>
Leaving aside whether or not there is a use-case for this, the reason they
aren't there is that they aren't needed. As the OP was already told, to
access argv, you simply import the 'sys' module and access sys.argv.
There are apis both to import modules and to get an attribute of an
existing Python object. So all you need is something like (untested):
PyObject *sys = PyImport_ImportModule("sys");
PyObject *argv = PyObject_GetAttrString(sys, "argv");
int argc = PyObject_Length(argv);
if (argc != -1) {
... use argc, argv ...
}
Py_DECREF(argv);
Py_DECREF(sys);
More information about the Python-list
mailing list