Boost logo

Boost Users :

Subject: [Boost-users] [python] Adding a path to sys.path
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2008-10-08 12:57:21


Hi,

I was wondering if the code below is correct for adding a path to sys.path
in Python. Note that this will occur before any modules have been
executed/imported through Boost.Python. I'm also embedding the interpreter,
which is why I am doing this. I'm not sure how it can obtain the
sys.__dict__ when I haven't imported sys, so explanation on this would be
helpful for me.

            using namespace boost::python;
            using namespace boost::filesystem;

            object sys = GetNamespace( "sys" );

            list syspath( sys["path"] );
            syspath.insert( 0, complete( path ).file_string() );
            sys["path"] = syspath;

Note that "path" is a boost::filesystem::path object containing the path I
wish to add to sys.path.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net