C API: getting sys.argv
williams.jasonscott at gmail.com
williams.jasonscott at gmail.com
Mon May 15 23:34:30 EDT 2006
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.
Thanks!
More information about the Python-list
mailing list