Python/C and PYTHONPATH

Samuel Walters swalters_usenet at yahoo.com
Mon Jan 5 23:05:43 CET 2004


Fair warning:  At this point, I couldn't even get the example you quoted
to link properly.  Of course, I didn't dig too deep, as I'm in a hurry.

throw this c code into a .h file (my name for it is envdump.h)

---code---
#include <stdio.h>

extern char **environ;

void fdump_env(FILE *fd)
{
    char **ptr;
    int i = 0;
    ptr = environ;
    while(ptr[i] != NULL)
    {
        fprintf(fd, "%i : %s\n", ptr[i]);
        i++;
    }
}


void dump_env()
{
    char **ptr;
    int i = 0;
    ptr = environ;
    while(ptr[i] != NULL)
    {
        printf("%i : %s\n", i, ptr[i]);
        i++;
    }
}
---code---

Now, just inside the main function (or, perhaps, wherever you please, but
I'd try the line right before the first if statement) call dump_env() and
it will spit out all the environment variables that your C program
received.  You might find something there that's of interest.

Or, call setenv ("man 3 setenv") to manually set a python-path.
you can use that in combo with getenv ("man 3 getenv") to append to an
existing PYTHONPATH, if you so choose.

Give it a go, please let me know how it turns out.  If this doesn't shed
some light on the matter I might have another idea once I'm not rushing
around.

HTH

Sam Walters

-- 
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
    Do you really want to go there?"""




More information about the Python-list mailing list