C API: getting sys.argv
Georg Brandl
g.brandl-nospam at gmx.net
Tue May 16 03:08:57 EDT 2006
williams.jasonscott at gmail.com wrote:
> John Machin wrote:
>> > PyObject *_argv = PyImport_ImportModule("sys.argv");
>>
>> What does the name of the function tell you? You can't do that in one
>> hit. Start with
>> PyObject *_sys = PyImport_ImportModule("sys");
>> then you need to get the module's argv attribute.
>
> I just figured this out, doh. Thanks.
>
>> However a better design might be have your extension module have an arg
>> which can be *any* list of strings. That makes it more flexible, at the
>> expense of making the caller pass sys.argv. But it would save you
>> having to muck about with importing "sys", then plucking out the
>> module's argv attribute.
>
> but this is great advice.
Actually, use can use PySys_GetObject("argv") instead.
Georg
More information about the Python-list
mailing list