C API: getting sys.argv

John Machin sjmachin at lexicon.net
Mon May 15 23:26:37 EDT 2006


> 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.

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.




More information about the Python-list mailing list