Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > C API: getting sys.argv

Reply
Thread Tools

C API: getting sys.argv

 
 
williams.jasonscott@gmail.com
Guest
Posts: n/a
 
      05-16-2006
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...

 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      05-16-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.

 
Reply With Quote
 
 
 
 
williams.jasonscott@gmail.com
Guest
Posts: n/a
 
      05-16-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!

 
Reply With Quote
 
Georg Brandl
Guest
Posts: n/a
 
      05-16-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You Mean I Won't Be GEtting Paid More for Getting This Cert? TBone MCSE 13 10-30-2007 01:10 PM
You Mean I Won't Be GEtting Paid More for Getting This Cert? TBone MCDST 7 10-30-2007 01:10 PM
Re: You Mean I Won't Be GEtting Paid More for Getting This Cert? FrisbeeŽ MCSE 0 10-22-2007 03:32 PM
Getting User Input after getting Input from a file dei3cmix@uga.edu C++ 3 03-23-2006 05:01 AM
How to avoid getting BGP routes while getting a router's routing table ncosta@net.ipl.pt Cisco 2 01-25-2006 11:50 AM



Advertisments