John Machin wrote:

>Duncan Booth wrote:
>  
>
>>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.
>>    
>>
>
>"no use-case" == "no need" in my book
>
>  
>
>>As the OP was already told, to 
>>access argv, you simply import the 'sys' module and access sys.argv.
>>    
>>
>
>Simple in Python, not in C.
>
>  
>
>>There are apis both to import modules and to get an attribute of an 
>>existing Python object.
>>    
>>
>
>I know that; my point was why should you do something tedious like that 
>when you shouldn't be interested in accessing sys.argv from a C 
>extension anyway.
>
>  
>
>> 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);
>>    
>>
I understand all the good arguments explained before, and I am agree 
with them.
Nevertheless, I implement Python bindings from a generic parallel 
framework and a new application based on this framework needs to call a 
kind of initilization class : the constructor arguments are argc and 
argv... Then, the previous solution can be a work around to test some 
behavours of my bindings.
Thanks for your answers ;-) 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to