C API: getting sys.argv

  • Thread starter williams.jasonscott
  • Start date
W

williams.jasonscott

Hi,

How would one go about getting sys.argv fom within the context of a C
API extention module? I want to pass it along to C library that I'm
calling from my module code.

TIA~

I'm trying to load the sys module using:

PyObject *_argv = PyImport_ImportModule("sys.argv");

but it is coming back NULL...
 
J

John Machin

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

williams.jasonscott

John said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top